我使用了以下宏,我在另一个论坛上找到了将一张工作表复制到多个其他工作表中:
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
我要复制到其他目标工作表的源工作表具有公式(与源文件中的其他工作表相关)。
运行宏后,目标工作表中的公式仍然引用源工作表而不是目标工作表。
如何修改宏以调整对新工作簿的引用?
提前非常感谢!
最好的,
亚瑟
最佳答案
您可以在复制工作表后删除插入的引用。例如,如果您的源工作簿名为“Source.xlsx”:
Cells.Replace What:="=[Source.xlsx]", Replacement:="=", LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
关于excel - 将工作表复制到多个工作簿 - 公式引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42951375/