【发布时间】:2021-12-21 18:00:09
【问题描述】:
我正在尝试更改我的公式从中提取的每月工作簿。
例如,我的公式之一是=C3-AVERAGE('W:\2021\09 - 2021\[September 2021 Reforecast.xlsx]Current Price Forecast'!F3:Q3)。
例如,我想从与 9 月文件的比较切换到 10 月。
我正在尝试使用替换功能将 "09 - 2021[September 2021 Reforecast.xlsx]Current Price Forecast" 替换为上述公式中的 10 月文件。
Sub vsOct()
Dim MyCell As Range
Dim ToReplace As String
Dim Replacement As String
Set MyCell = ThisWorkbook.Worksheets("Price Variance").Range("H3")
ToReplace = Range("N3").Value
Replacement = "W:\2021\10 - 2021\[October 2021 Reforecast.xlsx]"
MyCell.Value = Replace(expression:=MyCell.Value, Find:=ToReplace, Replace:=Replacement)
End Sub
代码放入一个硬编码值,如 1.913,而不是替换文件名的公式。
【问题讨论】:
-
如果您想替换该工作簿的 所有 链接,请考虑使用
Workbook.ChangeLink -
@chrisneilsen 我将如何让它只更改该表上的链接?
-
正如我在评论中所说的 如果您想替换该工作簿的所有链接。如果您只想更改一张纸上的链接,则必须找到另一种方法