我正在尝试使用以下VBA程序创建Excel工作簿的多个副本:
Public Sub DuplicateBookMultipleTimes()
Dim n As Integer
On Error Resume Next
n = InputBox("How many copies of the active workbook do you want to make?")
If n >= 1 Then
For numtimes = 1 To n
ActiveWorkbook.SaveCopyAs "C:\Users\fmhijan\Desktop\Awet data transfer\" & Workbooks(Workbooks.Count) & ".xlsm"
Next
End If
End Sub
我的预期结果是看到工作簿1,工作簿2,工作簿3……取决于我想要多少份。
我得到显示框并输入号码。该程序运行正常,但我在文件夹中看不到文件。请指教。感谢您的帮助。
答案 0 :(得分:1)
尝试一下:
Public Sub DuplicateBookMultipleTimes()
cFolder = "C:\Users\fmhijan\Desktop\Awet data transfer\"
nCopies = InputBox("How many copies of the active workbook do you want to make?")
If nCopies >= 1 Then
For nLoop = 1 To nCopies
ActiveWorkbook.SaveCopyAs cFolder & "workbook" & nLoop & ".xlsm"
Next
End If
End Sub