Solved

How to run Excel Macros from VB6

Posted on 2001-06-03
5
323 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
ID: 6151295
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
ID: 6151391
-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
ID: 6151429
I think I am on the right track now.

Cheers,
0
 
LVL 7

Expert Comment

by:q2eddie
ID: 6151435
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
ID: 6151510
-e2

I will be alright.

Cheers.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

911 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

27 Experts available now in Live!

Get 1:1 Help Now