![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 4
|
Does anyone know how to run an excel macro from visual basic? I have a lot of macros I want to use in a program I'm writing, and I can't figure out how to run the macros outside of Excel.
For instance: I want to push a button in a visual basic 6.0 project, then excel would open and the macro would run. Thanks for any help Shawn |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Richland, Washington
Posts: 91
|
Shawn -
I'm guessing that working out of pure Visual Basic isn't that different from cross-application VBA. Here's an example of code I would use to open Excel from Word: Sub excelsession() Dim xlapp As Excel.Application 'start excel... Set xlapp = CreateObject("Excel.Application") 'now let's see it... xlapp.Visible = True 'Add a workbook... xlapp.Application.Workbooks.Add 'or, open a specific workbook.. xlapp.Workbooks.Open "test.xls" End Sub For this to work, one must first load the Excel object models into your active library. I hope that gives you something to start with. Good Luck. Tom |
|
|
|
|
|
#3 |
|
New Member
Join Date: Feb 2002
Posts: 4
|
Thank you for the quick answer!
Is there any place i could go to figure out how to work objects??? I think this is where I'm getting hung up. Shawn |
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
'Run the "ExcelMacroTest" procedure stored in the workbook xlapp.Application.Run "YourNameOfTheMacroToRun" HTH Ivan |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|