本文介绍了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()
需要完整路径.尝试这样的事情:
Dir()
only returns the filename, but Workbooks.Open()
requires the full path. Try something like this:
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
这篇关于Excel VBA打开工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!