To create Workbook with Excel VBA, first thing we must specify which template we need to create such as Workbook with blank sheet, Chart, Macro, International Macro or Dialog. Each template represent by number or special command as below:
Workbook with Blank worksheet
OR
Workbooks.Add(xlWBATWorksheet)
Workbook with Chart Worksheet
OR
Workbooks.Add(xlWBATChart)
Workbook with Macro Worksheet
OR
Workbooks.Add(xlWBATExcel4MacroSheet)
Workbook with International Macro Worksheet
OR
Workbooks.Add(xlWBATExcel4IntlMacroSheet)
Base on my testing if we use Workbooks.Add(7) it will create Workbook with Dialog Worksheet. If we use number 5 or 6 the result is the same as Workbooks.Add(1) which Blank worksheet. If the number is greater than 7 "Run Time Error 1004 , Method Add of Object Workbooks Failed".
Sub CreateWorkbook()
'Variables Declaration
Dim MstWB As Workbook
'Change the number according to template
Set MstWB = Workbooks.Add(1)
End Sub
Thank You
Microsoft Reference (Workbooks)
Microsoft Reference (Workbooks.Add)
Microsoft Reference (xlwbatemplate)
No comments:
Post a Comment