Reputation: 532
I am trying to make a macro which Copies the Commission Calculation Tables into my Dental Commissions Report. The issue is that I have a fixed name "June Dental Commissions v5.xlsm" in the destination. Is there a way I could replace the "June Dental Commissions v5.xlsm" with a variable which I define as the current workbook in the macro?
Workbooks.Open Filename:= _
"X:\Customer Service\Dental Reports\Commission Report Calculation\Commission Calculation Tables.xlsx"
Sheets(Array("Entire Commission Table", "Zip & Terr List May 2013", _
"Abbreviation Finder")).Select
Sheets("Zip & Terr List May 2013").Activate
Sheets(Array("Entire Commission Table", "Zip & Terr List May 2013", _
"Abbreviation Finder")).Copy Before:=Workbooks( _
"June Dental Commissions v5.xlsm").Sheets(4)
Upvotes: 0
Views: 996
Reputation: 5962
If your macro is not in the active file, use this adaptation of Tim's code
Dim wb as Workbook, fName as string, fPath as string, wbDest as workbook
fPath = "X:\Customer Service\Dental Reports\Commission Report Calculation\"
fName = "Commission Calculation Tables.xlsx"
set wbDest=activeworkbook
Set wb = Workbooks.Open(fPath & fName)
wb.Sheets(Array("Entire Commission Table", "Zip & Terr List May 2013", _
"Abbreviation Finder")).Copy Before:=wbDest.Sheets(4)
wb.close(false)
Upvotes: 1
Reputation: 166331
Dim wb as Workbook, fName as string, fPath as string
fPath = "X:\Customer Service\Dental Reports\Commission Report Calculation\"
fName = "Commission Calculation Tables.xlsx"
Set wb = Workbooks.Open(fPath & fName)
wb.Sheets(Array("Entire Commission Table", "Zip & Terr List May 2013", _
"Abbreviation Finder")).Copy Before:=ThisWorkbook.Sheets(4)
Upvotes: 3