Running Excel Macro from VB6

R

Rick Griffith

I've got a VB6 program that runs an excel 2000 macro fine
if the spreadsheet is opened by user before running the VB
program. If user doesn't open the spreadsheet an error
occurs.

Is there a way to eliminate need for user to open the
spreadsheet?
 
B

Bob Phillips

Rick,

The workbook will have to be opened to run the macro, whether your user does
it or whether you do from your VB6 app.

If you want some code on opening the workbook, try something like

Set xlApp = CreateObject("Excel.Application")
If Not xlApp Is Nothing Then
xlApp.Workbooks.Open "D:\Bob\My Documents\My
Spreadsheets\Lastcount.xls"
xlApp.Visible = True
xlApp.Run "LastCount.xls!Test"
xlApp.Quit
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top