VBA更新链接的Excel工作簿的文件路径

时间:2019-03-08 21:16:06

标签: excel vba

我有一个大文件,它总结了几个工作簿,摘要文件中的链接每个月都会更新。enter image description here] 1

enter image description here

每个月,文件路径中唯一更改的是日期。例如,我需要将所有单元格从“ WE 1.27.19”更改为“ WE 2.24.19”。通过查找和替换,我被提示通过进入公司的共享驱动器并单击新文件来单独更改单元格。

enter image description here

是否有一个宏可以自动执行此操作?

1 个答案:

答案 0 :(得分:0)

如果主文件从未更改,也许:

Sub UpdateSomeLinks()

Dim wb As Workbook
Dim ws As Worksheet
Dim rngLinks As Range
Dim strDate As String

'sets variables
Set wb = myworkbook
Set ws = wb.Worksheets("myworksheet")
Set fd = Application.FileDialog(msoFileDialogFilePicker)

'input box for date
strDate = InputBox("Please type in new date")

'only loops through formula cells
For Each rngLinks In ws.UsedRange.SpecialCells(xlCellTypeFormulas)
    rngLinks.Formula = Replace(rngLinks.Formula, "olddate", strDate)
Next rngLinks

'cleanup
Set ws = Nothing: Set wb = Nothing
Set rngLinks = Nothing: Set fs = Nothing

End Sub

然后,也许是工作表上的一个调用上述Sub的按钮。