gpt4 book ai didi

vba - excel vba 打开工作簿

转载 作者:行者123 更新时间:2023-12-04 22:03:10 25 4
gpt4 key购买 nike

我的代码是:

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

关于vba - excel vba 打开工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30833126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com