+ Reply to Thread
Results 1 to 3 of 3

Runtime error with sheets.add

  1. #1
    ittac
    Guest

    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.Count)

    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

  2. #2
    Patrick Molloy
    Guest

    RE: 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.Count)
    >
    > 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


  3. #3
    Bob Phillips
    Guest

    Re: 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" <[email protected].(I_Hate_Spam)> wrote in message
    news:[email protected]...
    > 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.Count)
    >
    > 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




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1