How to run Excel Macros from VB6

Dear All,

I need someone to point me in the right direction on how to solve my problem, which is:

I have an Excel Template (I created) which includes some Macors written in VBA (I wrote them), I would like my program in VB to open this Excel Template and run the macros in it. Any idea to get me going?
LVL 1
khaledcAsked:
Who is Participating?
 
q2eddieConnect With a Mentor Commented:
Hi, khaledc.

<--------------- Sample Code Begins ------------->
Dim tmpSheet As Object
Set tmpSheet = CreateObject("excel.application")
' Set this to true only if you want to see the macro run.
tmpSheet.Visible = True
' Open the Excel spreadsheet file.
' Remember: AutoOpen will NOT execute if you
'           open the spreadsheet this way.
tmpSheet.workbooks.open "c:\temp\test_macro.xls"
' Run the macro.
tmpSheet.run "Macro1"
' You can close the spreadsheet.
' Note: "False" means that the spreadsheet will
'       close without warning.
'tmpSheet.workbooks("test_macro.xls").Close False
<--------------- Sample Code Begins ------------->

Bye. -e2
0
 
khaledcAuthor Commented:
-e2,

Will the excel sheet open be a subject of the VB?

In any case, I will try your suggestion and get back at you ASAP.

Cheers,
0
 
khaledcAuthor Commented:
I think I am on the right track now.

Cheers,
0
 
q2eddieCommented:
Hi, again.

>Will the excel sheet open be a subject of the VB?
Did you have further questions about this is or are you at the point where you can continue?

Bye. -e2
0
 
khaledcAuthor Commented:
-e2

I will be alright.

Cheers.
0
All Courses

From novice to tech pro — start learning today.