PDA

View Full Version : Calling Excel from VB



02-05-2002, 03:07 PM
Hi there,
I have a VB program that call Excel and loads some csv files in it.
When processing a second file I'd like to detect that Excell is already running and locate the exact sheet I need in the workbook being used by Excel (this is available as a private variable). All the examples on the web refer to CreateObject and GetObject but I have found no examples that refer to specific sheets, only examples that can open an existing *.xls file (workbook).
Any suggestion to 'HOW TO' directories is welcome.

Thank you all,

Marco

02-05-2002, 04:33 PM
I usually do this sort of thing the other way round - ie have an Excel Macro pass stuff to another app.

eg.
AppActivate App_Name, False ' go back to Application to pick up data - App_Name should be string or Variant containing the First part of the App_name as you would see it in the Dark blue title bar of its window. Typically for Excel this is 'Microsoft Excel -'

Workbooks(Book_Name).Activate ' tell Excel which book to open - may not be required if you only have one or can guarantee the one you want is currently active.

Worksheets(Sheet_Name).Activate ' Sheet_Name is String or Variant (can also use a number which is the tab order number. 1 is left most)

That should now have you point at the right sheet.

have fun