将工作表复制到多个工作簿 – 公式引用

我已经使用了下面的macros,我发现在另一个论坛上复制一个工作表到其他工作表:

Option Explicit Public Sub CopySheetToAllWorkbooksInFolder() Dim sourceSheet As Worksheet Dim folder As String, filename As String Dim destinationWorkbook As Workbook 'Worksheet in active workbook to be copied as a new sheet to the destination woorkbook Set sourceSheet = ActiveWorkbook.Worksheets("Sheet1") 'Folder containing the destination workbooks folder = "F:\temp\excel\" filename = Dir(folder & "*.xls", vbNormal) While Len(filename) <> 0 Debug.Print folder & filename Set destinationWorkbook = Workbooks.Open(folder & filename) sourceSheet.Copy before:=destinationWorkbook.Sheets(1) destinationWorkbook.Close True filename = Dir() ' Get next matching file Wend End Sub 

源工作表,我想要复制到其他目标工作表具有公式(与源文件中的其他工作表有关)。 运行macros之后,目标工作表中的公式仍然具有对源工作表的引用,而不是目标工作表。

我如何修改macros以调整对新工作簿的引用?

提前感谢!

最好的,亚瑟

复制工作表后,您可以删除插入的引用。 例如,如果您的源工作簿被命名为“Source.xlsx”:

 Cells.Replace What:="=[Source.xlsx]", Replacement:="=", LookAt:=xlPart _ , SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False