How to run an excel macro using QTP?

This post talks about a generic problem in our daily testing life.
Say I have a scenario where I need to generate some output through QTP and based on that output I need to do some operation in Excel.
There are two ways to do that Either generate the output first to and excel and try to excel coding through QTP or simple generate the output and call a inbuilt macro that will do rest. I found the later one is the best solution...

1.I have an excell sheet that needs to be run and execute its in built macro
2. After the executed result of the macro,I need to add that output excell to QTP and start QTP execution

We were having problems as the excell sheets data are dynamic and there was a manual intervention every time when we tried to do Step-1 and Step-2 one after another.
Later the solution is found..
The solution is:
Strat the QTP execution-->QTP will trigger the Macro--->Then it will import the executed sheet ---->do its normal execution.

The code is:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
'Replace "macroname", "params1", "param2" with' the appropriate values
objExcel.Run "macroname", "params1", "param2"
'If there is no parameter for your macro .You can leave this place blank
objExcel.Run "macroname",

Hope this will help you.

How to run an excel macro using QTP? How to run an excel macro using QTP? Reviewed by Animesh Chatterjee on January 02, 2009 Rating: 5

1 comment:

  1. Thanks, seems good, though need to try.
    Thanks a lot.


Powered by Blogger.