编译错误:添加表单button后未定义的子项或function

下面是我已经写了从多个工作表复制数据到一个新的主表,它正常工作的代码,直到我做了一点点改变我的代码添加一个表单button导入数据现在当我点击button我得到错误

编译错误:子或function未定义

谁能帮我 ? 这里是ImportFormbtnImportbutton的代码:

 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 

在这一行请删除引号,

 Set dirObj = mergeObj.Getfolder("folderpath") 

这会导致错误,因为它是一个variables。

应该是这样的,

 Set dirObj = mergeObj.Getfolder(folderpath)