Discussion Locked

VB6 abd Excel97

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need/want to be able to control an Excel workbook from a VB6 app, like you can with an Access DB. I need to be able to input values to specific cells, activate macros (one of which imports data from Access and one that exports to Word)...all fromthe environment of my application. I have the Access part mostly sorted out, but was wondering about the Excel side.
Can anyone help?

3 replies

by keith.hall1

Select Tools, Reference and click on tickbox for Microsoft Excel 8.0 of your VB application to use an early binding reference to the Excel Application
Sample code:
Declare a refrence to the Excel application:
Private wks as Excel.Application
'Private wks As Object ' is the alternative for a Late Binding object

To start the excel app either use for early binding:
Set wks = New Excel.Application
'Set wks = CreateObject("Excel.Application")'late binding
'wks.Visible = True ' depends on whether you wish to see it

Opening a specific spreadsheet:
wks.Workbooks.Open Filename:="yourexcel.wks"

Placing a specific value in cell a1 on sheet1:
wks.Workbooks("yourexcel.wks").Worksheets("sheet1").Range("a1").Value = 1

Running a sub called hello in ThisWorkBook with a string parameter
wks.Run "yourexcel.wks!ThisWorkBook.hello", "Hello world"

Save the sheet
wks.Workbooks(SimName).SaveAs Filename:=SaveName

This discussion is closed to new replies.