I was able to combine the three separate calls to three macros in the active master workbook into one single macro for the copy and paste to powerpoint.
I am trying to do the similar task with copy and pasting range from the active master workbook to three different workbooks which is currently driven by three separate macros.
1. 13M
2. YearQtr
3. Grid
I am unable to get the similar functionality. What am I doing wrong?
In this case the target file is three different files unlike the powerpoint target file which was one.
The below code is in my master file
Sub CopyTo13MHardCopy()
' CopyHardCopy Macro
'
'HFI
'copy_range_sheet(sheet, rngname)
copy_range_sheet "HFI", "HFI13M"
'copy_range_sheet "Agency", "Agency13M"
End Sub
Private Sub CommandButton2_Click()
Call CopyTo13MHardCopy
CopyToYearQtrHardCopy
'Call CopyToPrimeGridHardCopy
End Sub
Sub CopyToYearQtrHardCopy()
Workbooks.Open Filename:= _
"F:\Focus\Myfolder\Copy Paste Project\OnePagers_Templates\OnePagersYearQuarter_Template.xlsm"
Application.Run "OnePagersYearQuarter_Template.xlsm!Sheet1.CopyToYearQtrHardCopy"
Workbooks("OnePagersYearQuarter_Template.xlsm").Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub
The below module contains the funtion for the first sheet(13M) in the active workbook.
'Public Function copy_range(sheet, rowStart, columnStart, row_count, columnCount, slide, aheight, awidth, atop, aleft)
'Public Function copy_range(sheet, rngname, slide, aheight, awidth, atop, aleft, vscale)
Public Function copy_range_sheet(sheet, rngname)
'Dim Filename As String
'Set Filename = "F:\Focus\AnitaPradeep\Copy Paste Project\OnePagers_Templates\One Pagers_13Month ViewHardCopy.xlsx"
Sheets(sheet).Select
'Cells(rowStart, columnStart).Resize(row_count, columnCount).Select
Range(rngname).Select
' Make sure a range is selected
If Not TypeName(Selection) = "Range" Then
MsgBox "Please select a worksheet range and try again.", vbExclamation, _
"No Range Selected"
Else
Range(rngname).Activate
Selection.Copy
Workbooks.Open Filename:= _
"F:\Focus\Myfolder\Copy Paste Project\OnePagers_Templates\One Pagers_13Month ViewHardCopy.xlsx"
Sheets("HFI").Select
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save
ActiveWindow.Close
End If
End Function
The second workbook which contains the macro being called from the master workbook has the below module that calls the function.
'Public Function copy_range(sheet, rowStart, columnStart, row_count, columnCount, slide, aheight, awidth, atop, aleft)
'Public Function copy_range(sheet, rngname, slide, aheight, awidth, atop, aleft, vscale)
Public Function copy_range_sheet_qtr(sheet, rngname)
'Dim Filename As String
'Set Filename = "F:\Focus\Myfolder\Copy Paste Project\OnePagers_Templates\One Pagers_yr_qtr_viewHardCopy.xlsx"
Sheets(sheet).Select
'Cells(rowStart, columnStart).Resize(row_count, columnCount).Select
Range(rngname).Select
' Make sure a range is selected
If Not TypeName(Selection) = "Range" Then
MsgBox "Please select a worksheet range and try again.", vbExclamation, _
"No Range Selected"
Else
Range(rngname).Activate
Selection.Copy
Workbooks.Open Filename:= _
"F:\Focus\Myfolder\Copy Paste Project\OnePagers_Templates\One Pagers_yr_qtr_viewHardCopy.xlsx"
Sheets("HFI").Select
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save
ActiveWindow.Close
End If
End Function
The second workbook(yearQtr) has trhe below code in the main macro sheet.
Thanks