将XLSM保存为XLSX并让公式参考XLSX

时间:2015-10-01 23:28:30

标签: excel-vba vba excel

我在excel VBA项目中工作,我的项目在背景中填充我的工作表并保存为xlsx,因此我可以在后面打开并查看。

我遇到的问题是单元格仍然引用Excel Vba项目。有没有办法将工作簿保存为XLSX并让单元格引用新工作簿(XLSX)而不是(XLSM)

这是我用来保存的代码

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Copy
ActiveWorkbook.SaveAs Filename:="C:\Users\asuchadu\Desktop\myFileName.xlsx"
Workbooks("myFileName.xlsx").Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True

1 个答案:

答案 0 :(得分:0)

尝试在关闭新文件之前更新链接,例如

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Copy
ActiveWorkbook.SaveAs Filename:="C:\Users\asuchadu\Desktop\myFileName.xlsx"

With Workbooks("myFileName")

    If Not IsEmpty(.LinkSources(xlExcelLinks)) Then
        .ChangeLink "myFileName.xlsm", "myFileName.xlsx", xlExcelLinks
    End If

    .Close True

End With

Application.DisplayAlerts = True
Application.ScreenUpdating = True