Dear All, I run the following code script, then I get an error: "Variable not Defined. What could be the issue, is there an explanation to what is the correct variable not set in the script code?
[CODE:]
Sub ListSheetNamesInNewWorkbook()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.ActiveSheet
Set wb = Excel.Application.Workbooks.Add
Set wb = wb.Sheets(21)
For i = 1 To ThisWorkbook.Sheet.Count
wb.Cells(i, 1) = i
wb.Cells(i, 2) = ThisWorkbook.Sheets(i).Name
Next i
With objNewWorksheet
.Rows(1).Insert
.Cells(4, 2) = "Section"
.Cells(4, 2).Font.Bold = True
.Cells(2, 2) = "Table of Contents"
.Cells(2, 2).Font.Bold = True
.Cells(4, 6) = "Page"
.Cells(4, 6).Font.Bold = True
.Columns("A:B").AutoFit
End With
End Sub
[CODE:]
Sub ListSheetNamesInNewWorkbook()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.ActiveSheet
Set wb = Excel.Application.Workbooks.Add
Set wb = wb.Sheets(21)
For i = 1 To ThisWorkbook.Sheet.Count
wb.Cells(i, 1) = i
wb.Cells(i, 2) = ThisWorkbook.Sheets(i).Name
Next i
With objNewWorksheet
.Rows(1).Insert
.Cells(4, 2) = "Section"
.Cells(4, 2).Font.Bold = True
.Cells(2, 2) = "Table of Contents"
.Cells(2, 2).Font.Bold = True
.Cells(4, 6) = "Page"
.Cells(4, 6).Font.Bold = True
.Columns("A:B").AutoFit
End With
End Sub