我有这段代码,它在另一个模块中完美运行,但是当我将其复制到我现在正在使用的模块时,它会抛出
"error 1004 method open of object workbooks failed"
当我通过对话框输入文件或让程序自己决定时,在“Set TlWb”
线上,我不明白为什么,因为它看起来很平庸,而且在那里没有太多可能出错的选项。我非常确定我提供给程序的路径是正确的,并且一切都已DIM
正确处理。
代码如下:
'opens open prompt for ABII Parallel Import Tracker - Month/Year.xlsx, on cancel opens actual month
MsgBox "Select ABII Parallel Import Tracker - Month/Year.xlsx file to open. Cancel opens actual month"
With Application.FileDialog(msoFileDialogOpen)
.Show
If .SelectedItems.Count = 1 Then
TlWbPath = .SelectedItems(1)
End If
End With
If TlWbPath <> "" Then
Set TlWb = Workbooks.Open(TlWbPath)
Else: Set TlWb = Workbooks.Open(traceLogPath & "ABII Parallel Import Tracker - " & Format(Date, "mmm-yyyy") & ".xlsx")
End If
最佳答案
最后我终于明白了。输入文件已损坏,因此我手动打开它并重新保存。损坏是由于未将下拉列表的源复制到另一张纸上而引起的。
关于Excel 错误代码 1004 - 方法打开对象工作簿失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19931123/