我正在尝试制作一个宏,将委员会计算表复制到我的牙科委员会报告中。问题是我在目的地有一个固定名称“June Dental Commissions v5.xlsm”。有没有办法用一个变量替换“June Dental Commissions v5.xlsm”,我将其定义为宏中的当前工作簿?
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)
答案 0 :(得分:3)
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)
答案 1 :(得分:1)
如果您的宏不在活动文件中,请使用Tim的代码
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)