使用vba代码我在网络驱动器上打开Excel中的Excel文件。该错误返回到以下代码行。包含vba代码的文件位于服务器上的VM上。 它几天前突然停止工作(我怀疑有一些自动Windows更新或病毒软件更新,我无论如何也无法回滚。)
错误指向以下代码行: 设置Target_Workbook = Workbooks.Open(Target_Path)
该文件没有损坏,因为我可以用我的电脑(带有vba的那个和网络上的那个)打开它。 我还有这个文件的几个较旧的备份副本,它们曾经工作过,现在有相同的错误信息。
以下是上下文中的代码:
Dim Target_Workbook As Workbook
Dim Local_Workbook As Workbook
Dim Target_Path As String
Target_Path = "U:\DATABASES\Prod Sched\PlannedPallets.xls"
Set Target_Workbook = Workbooks.Open(Target_Path)
Set Local_Workbook = ThisWorkbook
Target_Data = Target_Workbook.Sheets("PlannedPallets").Range("A1:CZ50")
Local_Workbook.Sheets("PlannedPallets").Range("A1:CZ50") = Target_Data
Local_Workbook.Sheets("Criteria").Range("V25") = 0
On Error Resume Next
Application.DisplayAlerts = False
Application.EnableCancelKey = xlDisabled
'''''Close Target Workbook
Local_Workbook.Save
' Target_Workbook.Save
Target_Workbook.Close
Application.DisplayAlerts = True
答案 0 :(得分:0)
就我而言,它有助于以只读方式打开WB,然后将其另存为...
代替:
Set Target_Workbook = Workbooks.Open(Target_Path)
使用:
Set Target_Workbook = Workbooks.Open(Target_Path, ReadOnly:=True)