2
以下は、複数のシートのデータを新しいマスターシートにコピーするコードです。コードを少し変更して追加するまで今すぐボタンをクリックするとデータをインポートするフォームボタンコンパイルエラー:フォームボタンを追加した後にサブ関数が定義されていない
Compile Error: Sub or Function not defined
誰でも助けてくれますか?ここImportForm
でbtnImport
ボタンのコードは次のとおりです。
Private Sub btnImport_Click()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Dim folderpath As String
folderpath = Range("I5").Value
If Range("I5").Value = "" Then
MsgBox "Select the folder which contains the reports.", vbInformation, "Cannot Import."
Range("I2").Select
ElseIf FileFolderExists(folderpath) = False Then
MsgBox "Selected Folder Does Not Exist.", vbInformation, "Cannot Import."
Range("I5").Select
ElseIf Dir(folderpath, vbDirectory) = "" Then
MsgBox "Selected Folder Not Found.", vbInformation, "Invalid Folder Name."
Range("I5").Select
Else
Me.lblWait.Visible = True
Me.btnCancel.Visible = False
Me.btnImport.Visible = False
Application.ScreenUpdating = False
Application.StatusBar = "Collecting Data, Please Wait..."
Set mergeObj = CreateObject("Scripting.FileSystemObject")
'change folder path of excel files here
Set dirObj = mergeObj.Getfolder("folderpath")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
On Error Resume Next
'Change B3:H to the range your working on and also B in B65536 to any column required.
bookList.Worksheets(1).Range("B3:H350" & bookList.Worksheets(1).Range("B65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
'Below only change "B" column name to your required column name
Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
bookList.Close
Next
End If
End Sub
、このようにすべきですか? – user3598756
@ user3598756 VBAはデバッグ中にこの行をハイライト表示します: 'Private Sub btnImport_Click()' – Hazmat
'btnImport'という名前のボタンがありますか? – KyloRen