Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to call a vba macro from visual basic?

Status
Not open for further replies.

lbrooks

IS-IT--Management
Jan 20, 2004
42
0
0
US
I have created an application that imports an excel file to create individual word documents for each entry and then is suppose to save each word document as a PDF. The problem is that the Adobe Acrobat PDFMaker function for Visual Basic seems to be unstable, but the VBA function works. So I would like to call the VBA function from Visual Basic. Is this possible. If not, any suggestions?
 
Hi there,

as far as I understand you want to programmatically start
an excel macro from your code. Maybe this is helpful:

Create an excel file named e.g. "C:\Progs\MyCode.Xls"
Record or write the code necessary to perform the required operations in a Public Sub in any VBA module:

Public Sub MySub
Msgbox "Running"
... your code here
End Sub

In your code, launch excel, load the file and start the Sub:

Dim Excel as Object
Set Excel = CreateObject("Excel.Application")
Excel.Workbooks.Open "C:\Progs\MyCode.XLS", 0
Excel.Application.Run ("MyCode.XLS!MySub")
Excel.Application.Quit
Set Excel = Nothing

This should work in all Versions from Excel 97 up.

If you want to start a word macro, it should work with the same technique...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top