繁体   English   中英

Excel VBA打开工作簿

[英]excel vba open workbook

我的代码是:

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()需要完整路径。 尝试这样的事情:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM