LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Word opening

Solved!
Go to solution

Hi,

does anyone know why it doesn't work for me to open a word right away?

 

First I initialize where the word is (the path is c: \\ ProgramData \\) in MessagePopup is correct.

Fmt(wordPathName,"%s%s",g_UserProfile,"\\P07_GPT_VizZavady_L3.doc");
 initWordZavad(wordPathName);  //inicializuje formulář wordu 
MessagePopup ("Info", wordPathName);

 

Now I'm calculating some data to write.
Subsequent word path check.
And then the word should open for me and it won't open.

MessagePopup is correct.

	if(celkemZaznamu>0) //Zobrazení vyplněného protokolu
	{
	//GetProjectDir (wordPathName);
	//strcat (wordPathName, "\\P07_GPT_VizZavady_L3.doc");
	MessagePopup ("Ahoj", wordPathName);
    WordRpt_DocumentOpen (g_appHandle, wordPathName, &g_docHandle);//Zobrazí protokol
	MessagePopup ("Ahoj", wordPathName);
	SmazPoslStranku(pocetListu);
	WordRpt_GoToDocumentTop (g_docHandle);
	
	}

 

Couldn't there be a problem here? :

 

void initWordZavad(char *prtokolName)
{
 char wordPathName[MAX_PATHNAME_LEN];
 
  if (g_docHandle)
     {
       CA_DiscardObjHandle (g_docHandle);
       g_docHandle = 0;
     }
	 
  if (g_appHandle)
     {
       WordRpt_ApplicationQuit (g_appHandle, 0);
       CA_DiscardObjHandle (g_appHandle);
       g_appHandle = 0;
     }  

   // Open new Word application and open document
   WordRpt_ApplicationNew (FALSE, &g_appHandle);
   GetProjectDir (wordPathName);
   strcat (wordPathName, prtokolName);
   WordRpt_DocumentOpen (g_appHandle, wordPathName, &g_docHandle);
   
   WordRpt_AddPageNumbers (g_docHandle, WRConst_Footer,WRConst_AlignPageNumberRight, WRConst_TRUE);  //Umístění čísla na stránce 
   
}

 

I don't know how to do it, the file is located there, but it just won't open it.

Thank you for the advice.

Nice day

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

Hi, first of all, you must add a reasonable error checking in order to understand why things are not working: trapping the return value from the functions is the usual way to do it and Word Report instrument functions follow this rule, with negative return values indicating an error. Passing this value to CA_GetAutomationErrorString gives you a meaningful description of the error.

 

Second hint, I would test the function putting the file in another folder, just to be sure that you aren't getting protection errors accessing files in a system folder.



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 2 of 6
(4,263 Views)
Hi Roberto,

and where should I place this CA_GetAutomationErrorString in the code?
I place documents (word templates) in ProgramData.
g_UserProfile=getenv("ALLUSERSPROFILE");​

I had to put the files in a different folder than Program Files, because I would prevent windows from opening to open these files.


Thank you for your help
0 Kudos
Message 3 of 6
(4,238 Views)
Solution
Accepted by topic author MajklS

I've already figured it out, I've opened the document twice, so the document path was nonsense.

Thank you.
Nice day

 GetProjectDir (wordPathName);
  strcat (wordPathName, prtokolName);
0 Kudos
Message 4 of 6
(4,227 Views)

Ok, I'm happy to know that you solved your problem.

 

Regarding the error checking (something that I urge you to incorporate in your program) you could do something along this line:

 

error = WordRpt_DocumentOpen (g_appHandle, wordPathName, &g_docHandle);
if (error < 0) {
    CA_GetAutomationErrorString (error, message, 1024);
    MessagePopup ("Error!", message);
    goto EndOfFunction;
}

 



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 5 of 6
(4,221 Views)

Thanks for the advice Roberto.

I wish you a nice day.

 

0 Kudos
Message 6 of 6
(4,199 Views)