【问题标题】:Excel VBA: Automated Excel Backup Stopped Working due to "Compile Error: Cannot find file or library"Excel VBA:由于“编译错误:找不到文件或库”,自动 Excel 备份停止工作
【发布时间】:2016-05-13 05:10:41
【问题描述】:

我有一个库存 xls 文件,其中包括办公室的图表。打开 xls 时,VBA 会在进行任何更改之前自动备份文件。这在过去的一年里奏效了。今天它坏了。

昨天,文件工作正常。
1) 我在 xls 表中添加了一些信息 - 没什么异常;我在过去一年中添加的相同类型的信息。我没有编辑 VBA。 2) 我在带有办公室图表的选项卡中添加了一些对象(形状-圆形、正方形等)。

今天,该文件无法正常工作。
1) VBA 调试器在打开时出现错误:“编译错误:找不到文件或库。” 2) 许多文本框/形状已从图表的选项卡中消失。我没有删除它们。

更新 1:我在图表上移动了一个形状,所有文本框都重新出现了。

感谢任何解决此问题的建议。

'Saves an exact copy of the file upon opening it to the \Back_Tracker location and added today's date to the filename.
Private Sub Workbook_Open()
Dim WBPath As String, WBName As String, TimeStampStr As String, PassW As String

WBPath = ThisWorkbook.Path
WBName = ThisWorkbook.Name
'PassW = "something"

Const cstrBACKUP As String = "Backup_Tracker"

If InStr(1, WBPath, cstrBACKUP) = 0 Then        'prevent backups from making backups of themselves.

    TimeStampStr = Format(Now(), "YYYY-MM-DD_hh-mm_")

     'Application.StatusBar = "Saving backup..."
    ActiveWorkbook.SaveCopyAs Filename:=WBPath & Application.PathSeparator & cstrBACKUP & Application.PathSeparator & TimeStampStr & WBName
     'Application.DisplayStatusBar = False
     'Application.DisplayStatusBar = True
End If
End Sub

【问题讨论】:

    标签: excel compiler-errors backup vba


    【解决方案1】:

    我使用 Excel VBA 的经验是,代码有时会在打开时损坏。 Access 曾经也是这种情况,但我不确定这是否最终得到解决。

    我的解决方案是在每次编辑后制作备份副本,或者对 Excel 文件使用源代码管理。这是唯一确定的方法。

    【讨论】:

      【解决方案2】:

      发现问题。

      取消选中它,它现在正在工作。

      Reference

      1. 打开数据库或应用程序。

      2. 在设计视图中打开模块或按 ALT+F11 切换到 Visual Basic 编辑器。

      3. 在“工具”菜单上,单击“参考”。

      4. 清除标记为“缺失:”的类型库或对象库的复选框

      【讨论】:

        猜你喜欢
        • 2013-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多