I was following a VBA tutorial and write the exact code in excel 2007. However, I got a Runtime error 438, excel doesn't support this property or method.
Anyone know why? Please let me know, thank you.
Option Explicit
Sub createWorkbook()
'DECLARE VARIABLES
Dim lngPref As Long, wkbNew As Workbook
Dim strPrefix As String, intsheets As Integer, i As Integer
'CAPTURE USER PREFERENCE
lngPref = Application.sheetsinNeWorkbook
strPrefix = InputBox("Please enter your prefix", "New workbook")
intsheets = InputBox("number of sheets required", "New workbook")
'CREATE WORKBOOK CONTAINING 4 SHEETS
Application.SheetsInNewWorkbook = intsheets
Set wkbNew = Application.Workbooks.Add
'NAME SHEETS IN NEW Workbook
For i = 1 To intsheets
wkbNew.Worksheets(i).Name = strPrefix & "" & i
Next
'RESTORE USER PREFEREMCE
Application.SheetsInNewWorkbook = lngPref
End Sub
Anyone know why? Please let me know, thank you.
Option Explicit
Sub createWorkbook()
'DECLARE VARIABLES
Dim lngPref As Long, wkbNew As Workbook
Dim strPrefix As String, intsheets As Integer, i As Integer
'CAPTURE USER PREFERENCE
lngPref = Application.sheetsinNeWorkbook
strPrefix = InputBox("Please enter your prefix", "New workbook")
intsheets = InputBox("number of sheets required", "New workbook")
'CREATE WORKBOOK CONTAINING 4 SHEETS
Application.SheetsInNewWorkbook = intsheets
Set wkbNew = Application.Workbooks.Add
'NAME SHEETS IN NEW Workbook
For i = 1 To intsheets
wkbNew.Worksheets(i).Name = strPrefix & "" & i
Next
'RESTORE USER PREFEREMCE
Application.SheetsInNewWorkbook = lngPref
End Sub