ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Running Excel Macro from VB6 (https://www.excelbanter.com/excel-programming/274330-running-excel-macro-vb6.html)

Rick Griffith

Running Excel Macro from VB6
 
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?

Tom Ogilvy

Running Excel Macro from VB6
 
Check if the workbook is open - if not, then open it, then run the macro.

--
Regards,
Tom Ogilvy


"Rick Griffith" wrote in message
...
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?




Bob Phillips[_5_]

Running Excel Macro from VB6
 
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

--

HTH

Bob Phillips

"Rick Griffith" wrote in message
...
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?





All times are GMT +1. The time now is 12:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com