Results 1 to 2 of 2
  1. #1
    New Lounger
    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.

    Thanks all.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 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.

    For example:

    ' 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
    objWorkbook.Close SaveChanges:=True
    Set objWorksheet = Nothing
    Set objWorkbook = Nothing
    Set objXL = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts