Results 1 to 3 of 3

Thread: Excel sheets with many pages

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Posts
    74

    Question

    For the moment I opens Excel and create cells with values from a database.
    But now I want to create several different pages in the same Excel-spreadsheet and load with data depending on the contents in the database.
    Is there someone who knows how to create a new page and if it is possible to name the tabbs of the pages?
    And also to direct on what page the data should be written.

    This is my present code:
    ------------------------
    Set ExcApp = CreateObject("excel.application") 'starting excel
    ExcApp.DisplayAlerts = True
    Set ExcWB = ExcApp.Workbooks.Add
    Set Xls = ExcWB.Worksheets(1)

    'Check what fields that is in the databas and create a cell with data in excel.

    For Each fl In td.Fields
    Index = Index + 1
    Xls.Cells(1, Index).Value = fl.Name
    Xls.Cells(2, Index).Value = dbTable.Fields(fl.Name)
    'Adjust the cellwidth according to contents of database
    Maxlength = Len(fl.Name)
    If Len(dbTable.Fields(fl.Name)) > Maxlength Then
    Maxlength = Len(dbTable.Fields(fl.Name))
    End If
    Xls.Columns(Index).ColumnWidth = Maxlength + 1
    Next

    If Err.Number <> 0 Then Exit Sub
    On Error Resume Next
    Xls.SaveAs filnamn

  2. #2
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    Start Excel.

    Start the macro recorder and name the macro.

    Insert a worksheet. Double click on the name at the bottom. Type in a new name. Hit enter.

    Switch back to the original sheet.

    Turn off the macro recorder.

    Go look at the code.

    The beauty of Excel and macros is that you can get the VBA code for almost all operations (with the notable exception of selecting the next cell - activecell.offset(1,0).select).

    To make the recorded code work in VBA, you probably need to use the Excel object - like ExcApp.Sheets.Add.

    [Edited by billwagnon on 05-23-2000 at 09:32 AM]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Posts
    74

    Smile

    Thank you!

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