我正在尝试根据格式创建一个新的工作簿,就像现有的excel文件一样,我正在使用下面的代码
sub newWorkBook()
Dim newWorkBook as New WorkBook
Set newWorkBook = WorkBooks.Add("Template.xls")
/*It is erroring on the above line*/
newWorkBook.Application.DisplayAlerts = False
With newWorkBook
.SaveAs "C:\new.xls"
End With
domainWorkBook.Save
domainWorkBook.Application.DisplayAlerts = True
domainWorkBook.Close
Set newWorkBook = Nothing
End Sub
行Set newWorkBook = WorkBooks.Add("Template.xls")
上的错误表示下标超出了范围..
它还会打开一个名为Template1.xls的新Excel,并抛出错误......有什么建议吗?
答案 0 :(得分:0)
为什么不打开模板和 SaveAs 一个新名称?
Sub qwerty()
Workbooks.Open "C:\TestFolder\Template.xls"
ActiveWorkbook.SaveAs "C:\TestFolder\new.xls"
ActiveWorkbook.Close
End Sub