简体   繁体   English

在Excel 2003 VBA中更新链接时出现意外文件对话框

[英]Unintended file dialog when updating links in Excel 2003 VBA

I'm keeping sets of interrelated Excel 2003 spreadsheets for each of my company's projects. 我为公司的每个项目保留了一组相互关联的Excel 2003电子表格。

I want to copy some template XLS files to the project name and change the links that connect them to each other. 我想将一些模板XLS文件复制到项目名称,并更改将它们彼此连接的链接。

For example, the file TEMPLATE_ScanProgress.xls links to TEMPLATE_Film_Review.xls. 例如,文件TEMPLATE_ScanProgress.xls链接到TEMPLATE_Film_Review.xls。

I am copying them both to 123456_ScanProgress.xls and 123456_Film_Review.xls, and updating the link in 123456_ScanProgress.xls. 我将它们都复制到123456_ScanProgress.xls和123456_Film_Review.xls,并更新123456_ScanProgress.xls中的链接。

Sample code of what I'm doing: 我正在做的示例代码:

If Dir("WorkOrder & "_ScanProgress.xls") = "" Then
    FileCopy "TEMPLATE_ScanProgress.xls", WorkOrder & "_ScanProgress.xls"
    Workbooks.Open Filename:=WorkOrder & "_ScanProgress.xls", UpdateLinks:=0
    ActiveWorkbook.ChangeLink "TEMPLATE_Film_Review.xls", _
                              WorkOrder & "_Film_Review.xls", _
                              xlLinkTypeExcelLinks
    Workbooks(WorkOrder & "_ScanProgress.xls").Close SaveChanges:=True
Else
    FileExists = True
    FileExistsWarning_7 = WorkOrder & "_ScanProgress.xls"
End If

The problem is that when the code tries to update the link I get a file dialog asking me to choose a file for the change, even though I already specified which file I want in the code. 问题是,当代码尝试更新链接时,即使我已经在代码中指定了想要的文件,我也会看到一个文件对话框,要求我选择要更改的文件。

Try setting DisplayAlerts to False. 尝试将DisplayAlerts设置为False。 DisplayAlerts is on the Application object and is used to suppress dialog boxes for example when overwriting a file. DisplayAlerts位于Application对象上,用于例如在覆盖文件时隐藏对话框。 It may work in this case too. 在这种情况下也可能起作用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM