visual Basic and excel

srv656s

New Member
Joined
Feb 17, 2002
Messages
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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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
 
Upvote 0
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
 
Upvote 0
On 2002-02-18 16:24, srv656s wrote:
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

Hi Shawn, in order to run macros from the excel object just reference like;

'Run the "ExcelMacroTest" procedure stored in the workbook
xlapp.Application.Run "YourNameOfTheMacroToRun"


HTH

Ivan
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top