将工作表复制到其他工作簿,请参阅指向新的工作簿

这是我面对的情况:

我有两个工作表,“调查”和“configuration”的工作簿。 configuration工作表包含链接到测量工作表的单元格。

我正试图将这些工作表复制到一个新的工作簿。 但是,一旦完成了复制,新工作簿的“configuration”选项卡中的单元格就会指向旧的工作簿。 我想到的一个解决scheme是将值复制到新工作表/新工作簿中,但是我的客户不需要这样做:他们希望公式仍然存在,以防他们想要更新“测量”选项卡上的某些数据并将其发挥到configuration。

有没有办法复制工作表,使任何单元格引用保持不变(即仍指向“Survey!A1”而不是指向“OldWorkbook!Survey!A1”?

编辑我想使用工作表(数组(…))。复制方法。 我现在遇到的问题是,我有一个string数组与两个源工作簿通用的工作表的名称。 如果我将数组replace为数组(…),则代码将被炸毁。 不幸的是,我不会提前知道哪些工作表对于源工作簿是通用的,所以我不能对数组函数的列表进行硬编码,而且我已经尝试创build一个看起来像Array的参数列表的string,并使用它,但代码也不喜欢那样。

'Initialize indexes and arrays and stuff intSheetsInCommonIndex = 1 intDiscrepanciesIndex = 1 intSheetsInNPEIndex = 1 lngDiscrepancyBackColor = RGB(202, 6, 95) Application.ScreenUpdating = False For intInner = 1 To 40 strSheetsInCommon(intInner) = "" strSheetsInNPE(intInner) = "" Next intInner 'Set up the pointers to the two source workbooks. Set xlNPEWorkbook = Application.Workbooks.Open(Sheets("Combine PE Workbooks").txtNPEDocLocation) Set xlSPEWorkbook = Application.Workbooks.Open(Sheets("Combine PE Workbooks").txtSPEDocLocation) 'Now, fill the strSheetsInNPE array For Each xlNPECurrentSheet In xlNPEWorkbook.Sheets strSheetsInNPE(intSheetsInNPEIndex) = xlNPECurrentSheet.Name intSheetsInNPEIndex = intSheetsInNPEIndex + 1 Next xlNPECurrentSheet 'Now go through the SPE document. If the workhseet's name is in strSheetsInNPE, add that name to strSheetsInCommon. For Each xlSPECurrentSheet In xlSPEWorkbook.Sheets For intInner = 1 To intSheetsInNPEIndex If xlSPECurrentSheet.Name = strSheetsInNPE(intInner) Then strSheetsInCommon(intSheetsInCommonIndex) = xlSPECurrentSheet.Name intSheetsInCommonIndex = intSheetsInCommonIndex + 1 Exit For End If Next intInner Next xlSPECurrentSheet 'Turn alerts off (so that the messages about named ranges don't show up) and turn on the hourglass. Application.DisplayAlerts = False Application.Cursor = xlWait 'Create the combined document Set xlCombinedWorkbook = Workbooks.Add xlCombinedWorkbook.UpdateLinks = xlUpdateLinksNever 'Go through the NPE document and add all worksheets from there to the new workbook. xlNPEWorkbook.Worksheets(Array(strSheetsInCommon)).Copy xlCombinedWorkbook.Sheets(1) 

如果任何人有任何build议,我可以如何使用我的表名数组来做多页复制,我将不胜感激。

感谢您的帮助!

也许我忽略了一些细节,但为什么不简单地使用SaveAs将旧工作簿保存到新的工作簿? 参考资料将到位,您将有一个新的工作簿。