excel vba开放式工作簿
我的代码是:excel vba开放式工作簿,vba,excel,Vba,Excel,我的代码是: 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
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
Dim wb As工作簿
Dim MyObj作为对象,MySource作为对象,文件作为变量
file=Dir(“C:\Users\dlf164\Desktop\NE\”)
While(文件“”)
如果InStr(file,a)>0,则
设置wb=工作簿。打开(文件)
如果结束
file=Dir
温德
我收到的错误是应用程序或对象定义的运行时错误
如何解决此问题?Dir()
仅返回文件名,但工作簿。Open()
需要完整路径。试着这样做:
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
Dim wb As工作簿
Dim MyObj作为对象,MySource作为对象,文件作为变量
将路径设置为字符串
path=“C:\Users\dlf164\Desktop\NE\”
file=Dir(路径)
While(文件“”)
如果InStr(file,a)>0,则
设置wb=Workbooks.Open(路径和文件)
如果结束
file=Dir
温德
可能文件
不是Excel(兼容)文件?它是Excelcompatible@user3764484请给出答案(对所有的老问题都这样做)。在左侧的向上/向下箭头下方,有一个复选标记,单击它可接受。