0

我正在尝试制作一个将佣金计算表复制到我的牙科佣金报告中的宏。问题是我在目的地有一个固定名称“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)
4

2 回答 2

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)
于 2013-07-18T17:19:23.787 回答
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)
于 2013-07-18T17:25:33.910 回答