LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Macro instruction error. Please help!

When I click on a button I am trying to start a macro instruction, I don`t have any errors but it doesn`t execute.

Here is my code:

HRESULT runMacro (void)
{            
    HRESULT error = 0;
            SetWaitCursor (1);
    // Application.Run "Logiciel_FH.xls!Feuil1.Lancer_calculs  "   
            status = CA_VariantSetCString (&MyVariant, " Logiciel_FH.xls!Feuil1.Lancer_calculs");
            error = Excel_AppRun (ExcelAppHandle, NULL, MyVariant, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, NULL);
            CA_VariantClear(&MyVariant);
              // Application.Run "Logiciel_FH.xls!Feuil4.MAJ_data_FH  "  
            status = CA_VariantSetCString (&MyVariant, " Logiciel_FH.xls!Feuil4.MAJ_data_FH");
            error = Excel_AppRun (ExcelAppHandle, NULL, MyVariant, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, NULL);
            CA_VariantClear(&MyVariant);
 // Application.Run "Logiciel_FH.xls!Feuil5.MAJ_data_phy  "  
      status = CA_VariantSetCString (&MyVariant, "Logiciel_FH.xls!Feuil5.MAJ_data_phy");
            error = Excel_AppRun (ExcelAppHandle, NULL, MyVariant, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, NULL);
            CA_VariantClear(&MyVariant);
            SetWaitCursor (0);
    return 0;
}

PS: When I run using excel I click on a button who has assignated the macro instruction: Logiciel_FH.xls!Feuil1.Lancer_calculs, after that a new window appears and I set some values and I can press some other buttons who have assignated other macro instructions.
I am trying to do the same thing using CVI.

0 Kudos
Message 1 of 6
(4,817 Views)

Hi,

 

I guess you're using Excel Report Generation with LabWindows/CVI.

 

If your Macro is already registered in Excel, Why don't you use directly the RunMacro function?

 

You'll find some infos on that function in the following links:

Generating Microsoft Excel Reports with LabWindows/CVI

Running a Macro in Excel using LabWindows/CVI

 

Regards,

Olivier L. | Certified LabVIEW Developer


0 Kudos
Message 2 of 6
(4,798 Views)

I used the same code as in those examples.

 

I can`t run the macro instruction directly but that is not the problem...

 

After my code lines I added this text in red color:

"Logiciel_FH.xls!Feuil1.Lancer_calculs");
    error = Excel_AppRun (ExcelAppHandle, NULL, MyVariant, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, CA_DEFAULT_VAL,
                                  CA_DEFAULT_VAL, CA_DEFAULT_VAL, NULL);
            CA_VariantClear(&MyVariant);
     

if (status<0) goto Error;
  Error:   
             SetWaitCursor (0);
   
            if (error < 0)
                ReportAppAutomationError (error);

//ReportAppAutomationError

  static void ReportAppAutomationError (HRESULT hr)
{
    char errorBuf[256];
   
    if (hr < 0) {
        CA_GetAutomationErrorString (hr, errorBuf, sizeof (errorBuf));
        MessagePopup (APP_AUTOMATION_ERR, errorBuf);
    }
    return;
}
When I run the program i get this error: unknown error..

 

It may be because he doesn`t know "Logiciel_FH.xls!Feuil1.Lancer_calculs"??

 

 

 

0 Kudos
Message 3 of 6
(4,777 Views)

Hi,

 

Excuse me but "Unknown error" doesn't help me to understand what's happening. Do you have an error code, or a screenshot of the error?

Olivier L. | Certified LabVIEW Developer


0 Kudos
Message 4 of 6
(4,762 Views)
The value of the error is -2147352567.
In the Control Help says that if the value is -2147352567 then the parameter Info Error contains aditional informations about the error and that I should use CA_DisplayErrorInfo to see theis informations. When I use this and run the program I get a pop-up window with the message "Unknown error".
0 Kudos
Message 5 of 6
(4,745 Views)

Hi Annees,

it seems to me that you are using the ActiveX interface like in the example "excel2000dem" instead of the report generation toolkit.

 

If this is the case, 2 questions come to my mind:

1. Have you tried using the example program and running the macro included there? Does it works regularly?

2. I am puzzled by the part highlighted in red in this line:

status = CA_VariantSetCString (&MyVariant, " Logiciel_FH.xls!Feuil1.Lancer_calculs");

The procedure NI uses in that code does not mention the sheet from which to run the macro; instead it opens the sheet and runs the macro. Have you tried to operate in a similar way?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(4,740 Views)