Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

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?
0
khaledc
Asked:
khaledc
  • 3
  • 2
1 Solution
 
q2eddieCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now