前提・実現したいこと
エクセルに13個のシートがあります。
シート名は、以下の通りです。
表紙,1,2,3,4,5,6,7,8,9,10,11,12
1.表紙のセルA2に入力した文字をフォルダ名にしてデスクトップに保存
2.シート1~12のシートをそれぞれCSVファイルにして1のフォルダに保存
というマクロを組みたいですが、うまくいきません。
試したことへ作成したマクロを貼り付けました。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
ソースコード
試したこと
Sub 切り分け()
ActiveWindow.WindowState = xlMinimized
Dim path As String
Dim WSH As Object
Dim OpenFileName As String
Dim FolderName As String
'作成するフォルダ名
FolderName = Range("A2").Value
'特殊フォルダの取得
Set WSH = CreateObject("WScript.Shell")
'デスクトップの位置を取得
path = WSH.SpecialFolders("Desktop") & ""
'カレントフォルダ変更
ChDir path
'デスクトップに指定したフォルダがない場合作成する
If Dir(path & FolderName, vbDirectory) = "" Then
MkDir path & "\" & FolderName Application.ScreenUpdating = False
End If
Sheets("7").Select Sheets("7").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\7.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("8").Select Sheets("8").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\8.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("9").Select Sheets("9").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\9.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("10").Select Sheets("10").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\10.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("11").Select Sheets("11").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\11.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("12").Select Sheets("12").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\12.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("1").Select Sheets("1").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\1.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("2").Select Sheets("2").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\2.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("3(うるう年調整必要)").Select Sheets("3(うるう年調整必要)").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\3.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("4").Select Sheets("4").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\4.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("5").Select Sheets("5").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\5.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("6").Select Sheets("6").Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False ChDir "C:\Users\bd11\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\bd11\Desktop\6.csv", FileFormat:= _ xlCSV, CreateBackup:=False ActiveWindow.Close Sheets("スケジュール").Select
End Sub
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答2件
あなたの回答
tips
プレビュー