我正在开发一个项目,将许多数据透视表从多本书移动到一个主工作簿。我已经将源代码中的所有选项卡都移到了主书中,但现在我需要找到一些代码来破坏数据透视表和源书之间的链接。我认为粘贴特殊/值函数可以解决这个问题,但是我很难让它工作。我还要注意,VBA宏位于与主工作簿不同的工作簿中,因此这似乎使事情变得复杂。任何帮助将不胜感激!!
这是我到目前为止的代码
Option Explicit
Public Sub Run_Process()
Dim Y As String
Dim M As String
Dim MonthName As String
Y = "2016"
M = "01"
MonthName = "January"
'Opens the workbooks
Workbooks.Open Filename:="\\(Path)\" & Y & "\" & Y & M & "CD_1993 Source.xlsx"
Workbooks.Open Filename:="\\(Path)\" & Y & "\" & Y & M & "CD_1997 Source.xlsx"
Workbooks.Open Filename:="\\(Path)\" & Y & "\" & Y & M & "CD_2002 Source.xlsx"
Workbooks.Open Filename:="\\(path)\" & Y & "\" & Y & M & "CD_1993 Source2.xlsx"
Workbooks.Open Filename:="\\(path)\" & Y & "\" & Y & M & "CD_1997 Source2.xlsx"
Workbooks.Open Filename:="\\(path)\" & Y & "\" & Y & M & "CD_2002 Source2.xlsx"
'Adding New Workbook
Workbooks.Add
'Saving the Workbook
ActiveWorkbook.SaveAs Filename:="\\(path)\" & Y & "\" & Y & M & "CR_CUNA_Client_Report_Test.xlsx"
'Begin Copying and renaming the tabs from the source workbooks
Workbooks(Y & M & "CD_2002 Source2.xlsx").Sheets("2002").Copy Before:=Workbooks(Y & M & "CR_CUNA_Client_Report_Test.xlsx").Sheets(1)
Sheets("2002").Name = "2002 Rpt - " & MonthName & " " & Y
Workbooks(Y & M & "CD_2002 Source.xlsx").Sheets("Summ by Pool Year").Copy Before:=Workbooks(Y & M & "CR_CUNA_Client_Report_Test.xlsx").Sheets(1)
Sheets("Summ by Pool Year").Name = "2002 Summ by Pool Year"
Workbooks(Y & M & "CD_1997 Source2.xlsx").Sheets("1997").Copy Before:=Workbooks(Y & M & "CR_CUNA_Client_Report_Test.xlsx").Sheets(1)
Sheets("1997").Name = "1997 Rpt - " & MonthName & " " & Y
Workbooks(Y & M & "CD_1997 Source.xlsx").Sheets("Summ by Pool Year").Copy Before:=Workbooks(Y & M & "CR_CUNA_Client_Report_Test.xlsx").Sheets(1)
Sheets("Summ by Pool Year").Name = "1997 Summ by Pool Year"
Workbooks(Y & M & "CD_1993 Source2.xlsx").Sheets("1993").Copy Before:=Workbooks(Y & M & "CR_CUNA_Client_Report_Test.xlsx").Sheets(1)
Sheets("1993").Name = "1993 Rpt - " & MonthName & " " & Y
Workbooks(Y & M & "CD_1993 Source.xlsx").Sheets("Summ by Pool Year").Copy Before:=Workbooks(Y & M & "CR_CUNA_Client_Report_Test.xlsx").Sheets(1)
Sheets("Summ by Pool Year").Name = "1993 Summ by Pool Year"
Workbooks(Y & M & "CR_CUNA_Client_Report_Test.xlsx").Activate
'Dim Sh As Worksheet
' For Each Sh In (Format$(Y, "0000") & Format$(M, "00") & "CR_CUNA_Client_Report_Test.xlsx").Worksheets
' If Sh.Visible = True Then
' Sh.Activate
' Sh.Cells.Copy
' Sh.Range("A1").PasteSpecial Paste:=xlValues
'
' Sh.Range("A1").Select
' End If
' Next Sh
'Application.CutCopyMode = False
其中CR_CUNA_Client_Report_Test.xlsx是我正试图打破源工作簿链接的主表单......