cancel
Showing results for 
Search instead for 
Did you mean: 

Execute MS Excel Macro from TestComplete script

SOLVED
Frequent Contributor

Execute MS Excel Macro from TestComplete script

Good afternoon.  I have a web app that is using Excel data.  I am wondering if there is a way to filter the Excel data from TestComplete.  I have tried to exceute the following Excel macro from TC:

 

     function Test()

     {

   // Gets Excel objects

   var excel = Sys.OleObject("TransferDataM.xlsm");

 

   // Runs a macro

     excel.Run("Re_Sort")

     }

 

 

When the text executes I receive the followint error:

 

   Invalid class string: cannot obtain ClassID.
   Error location:
   Unit: "CAO_Automation\CAO_Automation\Script\Unit2"
   Line: 4 Column: 3.
 
Any thoughts as to what I am doing wrong?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Execute MS Excel Macro from TestComplete script

Try this:

function Test()
{
  var excel = Sys.OleObject("Excel.Application");
  excel.Visible = true;
  excel.Workbooks.Open("C:\\TransferDataM.xlsm"); // replace with your file path
  excel.Run("Re_Sort");
}

Helen Kosova
SmartBear Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.

View solution in original post

6 REPLIES 6
Moderator

Re: Execute MS Excel Macro from TestComplete script

Check one of the How-To's:   Run macros in MS Excel

-----
Joseph
Frequent Contributor

Re: Execute MS Excel Macro from TestComplete script

Thanks, Joe.  The script I used was taken from that article however. 

Moderator

Re: Execute MS Excel Macro from TestComplete script

Try this:

function Test()
{
  var excel = Sys.OleObject("Excel.Application");
  excel.Visible = true;
  excel.Workbooks.Open("C:\\TransferDataM.xlsm"); // replace with your file path
  excel.Run("Re_Sort");
}

Helen Kosova
SmartBear Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.

View solution in original post

Frequent Contributor

Re: Execute MS Excel Macro from TestComplete script

That worked.  Thank you, HKosova.  I appreciate the help. 

Contributor

Re: Execute MS Excel Macro from TestComplete script

Hi @HKosova ,

 

I tried the way you mentioned, it worked fine. But I want to pass arguments to the macro function. How can we achieve it?

Highlighted
Moderator

Re: Execute MS Excel Macro from TestComplete script

@anumolu9999 add the argument values after the macro name, like so:

excel.Run("MacroName", arg1, arg2, ...);

For details, see the Application.Run method page in Excel documentation.


Helen Kosova
SmartBear Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.
New Here?
Join us and watch the welcome video:
Top Kudoed Authors