LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to comp.lang.basic.visual.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default VB6 with Excel Objects: Please review my code

Hi,

I wrote that simple program to get an idea how to work with Excel
objects from VB.

It should (and actually does) create a new Excel workbook with three
worksheets named "1", "2" and "3" (in this order from left to right)
and save it.

Please look at the code below and let me know if this is a good way to
do it. Is there a way (and need) to streamline the code?

TIA

'============================================
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet

Dim i As Integer
Dim strFileName As String
Dim bAlerts As Boolean

On Error GoTo Quit

Set xlApp = New Excel.Application
xlApp.Visible = False
xlApp.SheetsInNewWorkbook = 1
Set xlWB = xlApp.Workbooks.Add
For i = 1 To 3
Set xlWS = xlWB.Worksheets.Add(After:=xlWB.Worksheets(i))
xlWS.Name = Str$(i)
Next i
bAlerts = xlApp.DisplayAlerts
xlApp.DisplayAlerts = False
xlWB.Worksheets("Sheet1").Delete
xlWB.Worksheets(1).Activate

' strFileName = xlApp.GetSaveAsFilename
strFileName = "C:\Temp\Temp.xls"

xlWB.Close SaveChanges:=True, FileName:=strFileName
xlApp.DisplayAlerts = bAlerts
Quit:
xlApp.Quit

Set xlWS = Nothing
Set xlWB = Nothing
Set xlApp = Nothing
'================================================= ==
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What does Show Ink in Excel, Review Tab, comment, do? E. Duke 462 Excel Worksheet Functions 0 August 8th 08 04:31 PM
review changes in workbook Farhad Excel Discussion (Misc queries) 2 June 3rd 07 05:10 AM
i have a fax sent to me for review but i cant open its saying i n loans New Users to Excel 3 August 25th 05 03:10 AM
excel review bar broke Excel Discussion (Misc queries) 2 May 5th 05 04:46 PM
Is there a quick way to see which objects have code attached? Terri[_4_] Excel Programming 2 September 12th 03 05:11 PM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"