简体   繁体   English

Excel打开只读工作簿时,对象“工作簿”的方法“打开”失败

[英]excel Method 'open' of object 'workbooks' failed error when opening a read only workbook

I have code that should open open a handfull of workbooks, pull key info and close them. 我的代码应该打开一本完整的工作簿,提取关键信息并关闭它们。 i can see the workbook loading but then when it is about to open i get the runtime error 1004 that says 我可以看到工作簿正在加载,但是当它即将打开时,出现运行时错误1004

Method 'open' of object 'workbooks' failed 对象“工作簿”的方法“打开”失败

My code is as follows and when i debug it takes me to the 2nd line under the do while statement: 我的代码如下,当我调试时,将我带到do while语句下的第二行:

 Sub OEEsummmary()
Dim Gcell As Range
Dim MySheet As Worksheet
Dim Txt$, MyPath$, MyWB$
Dim myValue As Integer
Dim x As Long
Dim v As Variant, r As Range, rWhere As Range

MyPath = "L:\Manufacturing Engineering\Samuel Hatcher\"
x = 2
Set MySheet = ActiveSheet

Application.ScreenUpdating = False

Do While MySheet.Range("A" & x).Value <> ""
    MyWB = MySheet.Range("A" & x).Text
    Workbooks.Open Filename:=MyPath & MyWB, ReadOnly:=True, IgnoreReadOnlyRecommended:=True
    Set Gcell = ActiveSheet.Range("E21")
        With MySheet.Range("A" & x)
            .Offset(0, 7).Value = Gcell.Value
        End With
    ActiveWorkbook.Close savechanges:=False
    x = x + 1
Loop

End Sub

I tried to change the different defined variable to variant as per instructions of other people who had the same issue but nothing worked. 我试图按照其他遇到相同问题但无济于事的人的指示,将不同的定义变量更改为variant。 Any help is greatly appreciated thanks! 任何帮助,万分感谢!

update* I moved the two file names that were an issue to the bottom of the list and every other file name opened and copied the info perfectly but when the loop got to the last two files it gives me that error. 更新*我将两个有问题的文件名移到列表的底部,其他所有文件名均打开并完美复制了信息,但是当循环到达最后两个文件时,出现了这个错误。 all of the files are manipulated copies of the bottom 2 so i dont see why it doesnt work 所有文件都是底部2的可操纵副本,所以我不明白为什么它不起作用

update2* it seems as though the only workbooks that give the error and wont load are the ones open on another computer in the network, when this program is run all the workbooks will be open on other computers update2 *似乎唯一出现错误且不会加载的工作簿是在网络中另一台计算机上打开的工作簿,运行此程序时,所有工作簿都将在其他计算机上打开

it turns out a few of the files were corrupted so when the code encountered this it didnt work. 事实证明,其中一些文件已损坏,因此当代码遇到此问题时,它不起作用。 the solution to this problem was to close the corrupted workbook then when I reopened it I clicked the arrow next to open and selected "open and repair" then saved a new copy of the file and the code ran smoothly 解决此问题的方法是关闭损坏的工作簿,然后当我重新打开它时,单击打开旁边的箭头并选择“打开并修复”,然后保存文件的新副本,代码顺利运行

暂无
暂无

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

相关问题 Excel错误代码1004 - 对象工作簿的方法打开失败 - Excel error code 1004 - method open of object workbooks failed 对象工作簿的方法打开失败错误 - Method open of object workbooks failed error 从Powershell启动时,VBA中的“对象&#39;工作簿&#39;的方法&#39;打开&#39;失败”,但直接从Excel调用时有效 - “Method 'Open' of object 'Workbooks' failed” in VBA when launched from a Powershell, but work when directly call from Excel 对象“工作簿”的方法“打开”失败 - Method 'Open' of object 'Workbooks' failed Microsoft Access 例程生成的 Excel 报告出现错误 1004:方法打开对象工作簿失败 - Excel Reports generated by Microsoft Access routine gets Error 1004: Method Open Object Workbooks Failed 运行时错误“1004”-对象“工作簿”的方法“打开”失败 - Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed 运行时错误“ 1004”:对象“工作簿”的方法“打开”失败 - Run-time error'1004': Method 'Open' of object 'Workbooks' failed 方法“添加”对象“工作簿”失败 - 使用vba Access 2007导入excel工作簿 - Method 'Add' of object “workbooks” failed - Importing excel workbook with vba Access 2007 打开工作簿时,Workbook_Open处理程序不在加载项中触发 - Workbook_Open handler not firing in add-in when opening workbooks 当其他工作簿打开时,使 VBA 表单仅读取一个工作簿 - make VBA form only read one workbook when other workbooks are open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM