Macro Runs Twice

  • Thread starter Anand Nichkaode
  • Start date
A

Anand Nichkaode

Hi all,

We are using Excel for reporting in our organization. Basically there is a
Java web application which instantiates Excel 2007 with an XLAM. This XLAM
opens a Report Template(an .xls, .xlsm file, name supplied as command line
parameter). The Template has a datasheet where we have multiple ranges and
the Reportsheet which shows the final report based on the data from the
Datasheet. The Reportsheet contains formulas to show the final output. It
could contain Charts/Graphs also. The data is fetched from SQL server and is
pasted on the Ranges. And finally when all the data is pasted and Macro is
run the Template is saved as a Final Report somewhere on the Report Server.

The Excel runs in the background in all this process. There could be
multiple instances of Excel running on the same box. The instances run under
separate WindowStation.

In this process depending on the options selected by the end user, the
Report options are applied on the final report workbook. The some of the
Report options are Run User Macro, Protect Workbook, Protect Worksheets,
Delete Macro code, etc.

I am facing a problem when it comes to running user Macro.

This is how I execute the macro present in the templte.

Application.Run(<macro name>)

The <macro name> passed above could have parenthesis in it e.g.
"MacroTest()" or the <macro name> could have parameters e.g. "MacroTest(1,
1231)"

If the <macro name> is not stripped off the parenthesis then the macro gets
executed twice. When the macro has parameters then the parenthesis could not
be stripped off and the macro gets executed twice.

If anybody have any idea please let me know as it is a blocking issue in our
process.

Any help appreciated.

Thanks in advance.
 
N

Nigel

Try running the code manually to debug, it sounds there is a lot going on
and unless you isolate the possible areas it will be impossible to remotely
diagnose.
 
A

Anand Nichkaode

The macro when run independently runs once.

The way it is called i.e. Application.Run("MacroTest(1,123)") is wrong and
right way is Application.Run("MacroTest, 1, 123")

You can do a simple test on your side by calling a macro with parethesis, it
should run twice. The macro need not have parameters.

-Thx
Anand
 
D

Dave Peterson

Remove the ()'s.

Application.Run(<macro name>)

should be

Application.Run <macro name>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top