Worksheets.Add

B

Bruce Lindsay

I have code in my workbook code that attempts to create a new sheet when the
workbook opens. I used:

set oDoc = Workbooks.thisWorkbook
oSht = oDoc.Add(after:=1)

I get an error 1004. It doesn't add a sheet. Do I need to declare the
workbook and sheet object?

Bruce
 
T

Tom Ogilvy

Dim oDoc As Workbook
Dim oSht As Worksheet
Set oDoc = Application.ThisWorkbook
Set oSht = oDoc.Worksheets.Add(after:=oDoc.Worksheets(1))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top