Solved

How to run Excel Macros from VB6

Posted on 2001-06-03
5
312 Views
Last Modified: 2011-09-20
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
Comment
Question by:khaledc
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
q2eddie earned 50 total points
Comment Utility
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
 
LVL 1

Author Comment

by:khaledc
Comment Utility
-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
 
LVL 1

Author Comment

by:khaledc
Comment Utility
I think I am on the right track now.

Cheers,
0
 
LVL 7

Expert Comment

by:q2eddie
Comment Utility
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
 
LVL 1

Author Comment

by:khaledc
Comment Utility
-e2

I will be alright.

Cheers.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now