ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Called macro runs twice in excel 2002 (https://www.excelbanter.com/excel-programming/276587-re-called-macro-runs-twice-excel-2002-a.html)

Tom Ogilvy

Called macro runs twice in excel 2002
 
what fires the original macro? Is it tied to an event? I would put a
msgbox in the original macro just before the run command and see if the
original macro is running twice as well.

--
Regards,
Tom Ogilvy

"Martin French" wrote in message
...
Hi Everyone. This one really has me stumped but I'm sure
the answer is dead simple. I have written a macro in one
spreadsheet which then calls a macro from another. The
control then passes back to the original macro. It was
created in XL97 under windows98SE. My machine has now been
upgraded to XP and XL2002. When I run the macro now, it
runs the called procedure twice before returning to the
original coding. Does anyone know why this happens and is
there a way to stop it?

I have simplified the code for the purpose of
demonstrating this unusual behaviour.
The line of code in the main macro which calls the
secondary macro is:

application.run "2ndplacedatabase_sept_2003.xls!dummymacro
()"
End

The code in the secondary sheet is:

Sub dummymacro()
MsgBox "Now in the dummy macro"
End Sub

When I run this simple code the message box in the
secondary macro appears twice before control passes back
to the main macro.

Many Thanks to anyone who can help




Tom Ogilvy

Called macro runs twice in excel 2002
 
Good catch - I can reproduce it in xl2000 as well. I can't say why either.

--
Regards,
Tom Ogilvy

"Andy Pope" wrote in message
...
Hi Tom,

I can generate the problem and solution with two very simple macros, in
the same workbook.

Sub A
MsgBox "Sub A"
End Sub
Sub B
Application.Run "A()"
End Sub

If you remove the open and close brackets all works as expected.
i.e.
Sub B
Application.Run "A"
End Sub

Trouble is I do not know why.

Tom Ogilvy wrote:

what fires the original macro? Is it tied to an event? I would put a
msgbox in the original macro just before the run command and see if the
original macro is running twice as well.


--

Cheers
Andy

http://www.andypope.info





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com