Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Execute Macros from Other workbooks on current workbook

I'd like to be able to execute a macro I've got in A.XLS on the data in
B.XLS. I'm doing this from within a VB6 app. The code I've got seems to
work great for simple executions of Macros within the same workbook, namely:

workbookObject.Application.Run sMacroName, sarg1, sarg2 ....

If sMacroName is something like "Sheet1.Macro2" all is well. However if I
try something like sMacroName = "e:\temp\B.XLS!Sheet1.Macro2" I get one of
several issues. First error I've seen while attempting in VB6 is:

"The file cannot be opend because your virus scanner has detected a problem
with the file".

If instead I attempt this via VBA code within Excel itself like so:

Run "e:\delme\tryme3.xls!ThisWorkbook.Hello"

I get an error "The macro 'e:\delme\tryme3.xls!ThisWorkbook.Hello' cannot be
found.

I know within the VBA of Excel is at least gettting to the point where it
opens the file, but for some reason it says it cannot find the macro. If I
rename the file to something that does not exist and run the same line of
code above, I get the same error as within the VB6 code, namely:
"The file cannot be opend because your virus scanner has detected a problem
with the file".

Any help is greatly appreciated.

Allen Segall
(Softinterface, Inc.)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Execute Macros from Other workbooks on current workbook

Allen,
I assume you have an object reference to the Excel application.
Also, I believe the workbook with the macro you are calling must be open...

Dim vReturnValue as Variant
vReturnValue = appXL.Run("A.xls!MacroName", sArg1, sArg2)
- or -
appXL.Run "A.xls!MacroName", sArg1, sArg2

Both of the above should work if the file is open, so try opening the file first
then run the code. If the file won't open, that is a different issue.

It appears to me that it would be simpler to duplicate the code
and run it from your VB app.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Allen"
wrote in message
I'd like to be able to execute a macro I've got in A.XLS on the data in
B.XLS. I'm doing this from within a VB6 app. The code I've got seems to
work great for simple executions of Macros within the same workbook, namely:

workbookObject.Application.Run sMacroName, sarg1, sarg2 ....

If sMacroName is something like "Sheet1.Macro2" all is well. However if I
try something like sMacroName = "e:\temp\B.XLS!Sheet1.Macro2" I get one of
several issues. First error I've seen while attempting in VB6 is:

"The file cannot be opend because your virus scanner has detected a problem
with the file".

If instead I attempt this via VBA code within Excel itself like so:

Run "e:\delme\tryme3.xls!ThisWorkbook.Hello"

I get an error "The macro 'e:\delme\tryme3.xls!ThisWorkbook.Hello' cannot be
found.

I know within the VBA of Excel is at least gettting to the point where it
opens the file, but for some reason it says it cannot find the macro. If I
rename the file to something that does not exist and run the same line of
code above, I get the same error as within the VB6 code, namely:
"The file cannot be opend because your virus scanner has detected a problem
with the file".

Any help is greatly appreciated.

Allen Segall
(Softinterface, Inc.)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute Macros through Hyperlinks. [email protected] Excel Programming 6 January 18th 06 10:00 AM
How to execute Macros through Text Links? Sheikh Saadi Excel Discussion (Misc queries) 0 January 17th 06 07:02 PM
How to execute macros not saved in a workbook David P.[_3_] Excel Programming 0 April 1st 04 02:51 AM
Execute macros under Excel and Oulook XP POV Samnang Excel Programming 1 September 10th 03 06:40 AM
Execute macros under Excel and Oulook XP Dick Kusleika Excel Programming 0 September 4th 03 06:49 PM


All times are GMT +1. The time now is 07:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"