|
-
May 21st, 2000, 10:41 PM
#1
Thread Starter
Lively Member
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
-
May 21st, 2000, 11:58 PM
#2
Hyperactive Member
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]
-
May 22nd, 2000, 01:44 PM
#3
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|