Results 1 to 2 of 2
2002-11-26, 15:04 #1
- Join Date
- Feb 2002
- Thanked 0 Times in 0 Posts
Can VB6 do everything VBa Excel can? (vb6 office2k)
Having become somewhat literate in Excel VBA, can I switch to VB6 and do the same things to Excel files?
Is there a newbie FAQ outlining the added features vs lost features?
My impressions are: VBA Excel macros can only be run once Excel is up and running, thus making
the Excel Objects nebulae available. If VB6 would trigger this same nebulae to become awake, then it
might be able to talk to workbooks and sheets using the same code, with expaneded flexibility, and not
need to seem to open Excel and its user interface.
2002-11-26, 15:48 #2
- Join Date
- Mar 2002
- Thanked 29 Times in 29 Posts
Re: Can VB6 do everything VBa Excel can? (vb6 office2k)
You need to use Automation to handle Excel workbooks etc. in VB6.
In VB6, select Project/References...
Locate the Microsoft Excel 9.0 Object Library in the list and check the corresponding box. Click OK to close the References dialog.
Now you can use Excel code in your project, and you can use Intellisense for properties and methods, but you must create an Excel application object to do this - in fact, you will be running Excel, although it will remain invisible unless you decide otherwise.
' Declare object variables
Dim objXL As New Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objWorksheet As Excel.Worksheet
' Open a workbook
Set objWorkbook = objXL.Workbooks.Open("C:MyFilesMyWorkbook.xls")
Set objWorksheet = objWorkbook.Worksheets("Finances")
' Do something useful
' Finally, get out and clean up
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objXL = Nothing