特定のフォルダからファイルを開き、以下のコードで処理します。 しかし、VBAが最初のファイルを開くと、VBAは停止します。 私を助けてください!VBA - 特定のフォルダからファイルを開き、処理を実行します。
Sub ExtractData?()
'
' ExtractData? Macro
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Dim buf As String
Dim dlg As FileDialog
Dim fold_path As String
Application.ScreenUpdating = False
Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
If dlg.Show = False Then Exit Sub
fold_path = dlg.SelectedItems(1)
buf = Dir(fold_path & "\*.xlsx")
Do While buf <> ""
Workbooks.Open fold_path & "\" & buf
Sheets("データセット1").Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("Workbook.xlsm").Activate
Sheets("GE").Select
Cells(Range("A65536").End(xlUp).Row + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Workbooks(buf).Close SaveChanges:=False
buf = Dir()
Loop
End Sub
どこで停止しますか?どの行ですか? –
'Do While Len(buf)> 0'を試してください。 – nightcrawler23
最初のファイルを開いた後に停止します。 Btw、投稿を編集していただきありがとうございます。 – Tuan