Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
excel vba开放式工作簿_Vba_Excel - Fatal编程技术网

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请给出答案(对所有的老问题都这样做)。在左侧的向上/向下箭头下方,有一个复选标记,单击它可接受。