excel vba打开工作簿
我的代码是:
Dim wb As Workbook Dim MyObj As Object, MySource As Object, file As Variant file = Dir("C:\Users\dlf164\Desktop\NE\") While (file <> "") If InStr(file, a) > 0 Then Set wb = Workbooks.Open(file) End If file = Dir Wend
我收到的错误是应用程序或对象定义的运行时错误 。
如何解决这个问题?
Dir()
只返回文件名,但Workbooks.Open()
需要完整的path。 尝试这样的事情:
Dim wb As Workbook Dim MyObj As Object, MySource As Object, file As Variant Dim path As String path = "C:\Users\dlf164\Desktop\NE\" file = Dir(path) While (file <> "") If InStr(file, a) > 0 Then Set wb = Workbooks.Open(path & file) End If file = Dir Wend