Results 1 to 2 of 2

Thread: Creating new excel sheets with Vb

  1. #1

    Thread Starter
    New Member zwappy's Avatar
    Join Date
    Apr 2001
    Posts
    13
    I´m trying to create a workbook with a lot off sheets in. If a specific sheet does not exist, a new should be added. Anyone whith an idea?
    Everything in Vb

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Code:
     '#### IN THE WORKBOOK ####
    Public ShtCount As Integer
    'Set up a integer variable to keep track of the workbooks
    'number of sheets - declaring this publically means that this
    'variables accessible to all the subs through out the project
    'the worksheet and related worksheets
    
    Private Sub Workbook_Open()
     'when this workbook first opens ...
        ShtCount = Worksheets.Count
         'set the value of our integer variable to the
        'count of the number of worksheets
    End Sub
    
     '#### IN THE WORKSHEET #### 
    Private Sub Command1_Click()
        If Worksheets.Count < ShtCount Then
            Worksheets.Add
            Worksheets(ShtCount).Select
             'add a new worksheet and select it
            ShtCount = ShtCount + 1
             'update our number count of sheets by 1
        End If
    End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

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



Click Here to Expand Forum to Full Width