
06-01-2003, 09:30 PM
|
|
Regular
|
|
Join Date: Sep 2001
Location: Mokane, MO
Posts: 98
|
|
|
Here's the code I use to create a Workbook from a VB app:
----------------------------------------------------------------
Dim xlsfilename As String 'Needed for the Excel commands
Dim xlApp As excel.Application 'Needed for the Excel commands
Dim wkbNewBook As excel.Workbook 'Needed for the Excel commands
Dim wksSheet As excel.Worksheet 'Needed for the Excel commands
xlsfilename = App.Path & "\test.text"
'---- Creates a new hidden instance of Excel ----
Set xlApp = New excel.Application
Set wkbNewBook = xlApp.Workbooks.Add 'Creates the workbook
xlApp.ActiveSheet.Name = "test1" 'Creates a Worksheet called "test1"
'---- Do whatever you want in this section ----
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
'Makes a ew sheet
Worksheets("Sheet2").Activate 'Makes sheet2 active
xlApp.ActiveSheet.Name = "Test2t" 'renames sheet2 to test2
'---- Save and Quit Excel ----
xlApp.DisplayAlerts = False 'Keeps any save popups from happening
ActiveWorkbook.Close SaveChanges:=True, FileName:=xlsfilename
xlApp.Quit '**Remember to close Excel!
Set wkbNewBook = Nothing
Set xlApp = Nothing
|
|