Excel 错误代码 1004 - 方法打开对象工作簿失败

标签 excel runtime-error vba

我有这段代码,它在另一个模块中完美运行,但是当我将其复制到我现在正在使用的模块时,它会抛出

"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/

相关文章:

javascript - 使用closedxml从web api下载excel文件

c - 免费(): invalid next size(fast) error

SQL Access 记录 "Allow multiple value"

C# - 打印目录中的所有文件

excel - 如何使用另一列作为excel中的标准从一列中查找最大值

python - Python-Kivy:SoundLoader.load不起作用

PHP 生成的 XML 显示无效的 Char 值 27 消息

vba - PowerPoint 以编程方式查找和删除动画/效果

mysql - 从 VBA 记录集中获取表时出错

Excel VBA 错误 : Definitions of property procedures for the same property are inconsistent