I'm setting up a copy/paste macro for my financial model.
While it is currently running just fine, I am having trouble making if I save a new version of the model. The model has basic tabs I need to paste over as well as several tabs that operate on toggles and cycle through 10-15 sheets, so I have pasted an example of one sheet and one cycle in the code.
Copy_PasteWorkbook.xlsm is a blank excel document utilized as the location of the pasting.
Right now it will only work if I define the name of the file its running in and I cannot get Workbook(ThisWorkbook) to work in the code.
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
Application.Calculate
Windows("Copy_PasteWorkbook.xlsx").Activate
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Model"
Windows("XYZ_v1.xlsm").Activate
Sheets("Value_Summary_Sheet").Select
Range(Cells(1, 1), Cells.SpecialCells(xlCellTypeLastCell)).Select
Selection.Copy
Windows("Copy_PasteWorkbook.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=8
Sheets("Model").Select
Sheets("Model").Name = Cells(1, 3).Value
Range("A1").Select
Application.CutCopyMode = False
Windows("XYZ_v1.xlsm").Activate
Range("A1").Select
Sheets("Inputs").Range("Selected_Toggle_Number").Value = 1
Do Until Sheets("Inputs").Range("Selected_Toggle_Number").Value > Sheets("Inputs").Range("Total_Toggles").Value
Application.Calculate
Windows("Copy_PasteWorkbook.xlsx").Activate
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Model"
Windows("XYZ_v1.xlsm").Activate
Sheets("Financial Models").Select
Range(Cells(1, 1), Cells.SpecialCells(xlCellTypeLastCell)).Select
Selection.Copy
Windows("Copy_PasteWorkbook.xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=8
Sheets("Model").Select
Sheets("Model").Name = Cells(1, 3).Value
Range("A1").Select
Application.CutCopyMode = False
Windows("XYZ_v1.xlsm").Activate
Range("A1").Select
Sheets("Inputs").Range("Selected_Toggle_Number").Value = Sheets("Inputs").Range("Selected_Toggle_Number").Value + 1
DoEvents
Loop
Sheets("Inputs").Range("Selected_Toggle_Number").Value = 1
Sheets("Inputs").Select
Range("A1").Select
Application.CommandBars("Clipboard").Visible = True
On Error Resume Next 'incase clipboard IS empty
Application.CommandBars("Clipboard").FindControl(ID:=3634).Execute
Application.CommandBars("Clipboard").Visible = False
Application.ScreenUpdating = True
End Sub
Ideally I would like to sub out the Windows("XYZ_V1.xlsm").Activate code with ThisWorkbook so that it can function whenever changes are made to the model. Right now if I update and save a new version I then have to update the code throughout for the new name.
Workbook(ThisWorkbook)useThisWorkbook.Sheets("Sheet1")Please format all code in your questions - GMalc