Forum Discussion

DCat1223's avatar
DCat1223
Frequent Contributor
9 years ago
Solved

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?

 

  • HKosova's avatar
    HKosova
    9 years ago

    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");
    }

6 Replies

    • DCat1223's avatar
      DCat1223
      Frequent Contributor

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

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        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");
        }