ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Runtime error with sheets.add (https://www.excelbanter.com/excel-programming/336872-runtime-error-sheets-add.html)

ittac

Runtime error with sheets.add
 
Hi NG,

probably this question has been asked before, but I couldn't find an answer.
Problem:
I have a Excel 2003 - VBA-module. In this module I need to create a new sheet.
the code looks like this:

Dim NameOfWorkbook as string
NameOfWorkbook = ThisWorkbook.Name

Workbooks(NameOfWorkbook).Sheets.Add
after:=Workbooks(NameOfWorkbook).Sheets(Sheets.Cou nt)

if I try to add a sheet manually, everything works fine.

But I get a Runtime error "-2147319784 (80028018)
Method Add of object sheets failed"
when I try to add thew sheet using the code.

Any help would be greatly appreciated.

Regards
Bodo

Patrick Molloy[_2_]

Runtime error with sheets.add
 
Worksheets.Add after:=Worksheets(Worksheets.Count)

"ittac" wrote:

Hi NG,

probably this question has been asked before, but I couldn't find an answer.
Problem:
I have a Excel 2003 - VBA-module. In this module I need to create a new sheet.
the code looks like this:

Dim NameOfWorkbook as string
NameOfWorkbook = ThisWorkbook.Name

Workbooks(NameOfWorkbook).Sheets.Add
after:=Workbooks(NameOfWorkbook).Sheets(Sheets.Cou nt)

if I try to add a sheet manually, everything works fine.

But I get a Runtime error "-2147319784 (80028018)
Method Add of object sheets failed"
when I try to add thew sheet using the code.

Any help would be greatly appreciated.

Regards
Bodo


Bob Phillips[_6_]

Runtime error with sheets.add
 
Unqualified references?

Dim NameOfWorkbook as string
NameOfWorkbook = ThisWorkbook.Name

With ThisWorkbook
.WorkSheets.Add after:=.WorkSheets(.WorkSheets.Count)
End With

--
HTH

Bob Phillips

"ittac" .(I_Hate_Spam) wrote in message
...
Hi NG,

probably this question has been asked before, but I couldn't find an

answer.
Problem:
I have a Excel 2003 - VBA-module. In this module I need to create a new

sheet.
the code looks like this:

Dim NameOfWorkbook as string
NameOfWorkbook = ThisWorkbook.Name

Workbooks(NameOfWorkbook).Sheets.Add
after:=Workbooks(NameOfWorkbook).Sheets(Sheets.Cou nt)

if I try to add a sheet manually, everything works fine.

But I get a Runtime error "-2147319784 (80028018)
Method Add of object sheets failed"
when I try to add thew sheet using the code.

Any help would be greatly appreciated.

Regards
Bodo





All times are GMT +1. The time now is 05:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com