LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Display MS Word Doc in a panel not working?

Hi,

 

I'm trying to simply display a word doc in a panel.  I'll later customize font/colors, etc. but for now would be happy just to see it display!  Note I don't want to launch the Word App in another window, I want it in my own panel.

 

I used the activeX controller Wizard to create a Microsoft Word 15.0 Object Library.  My project now has the .fp file and .h file with the MS Word activeX functions available.

 

I made a .uir file with a simple panel TSTPANEL and created simple test case code, which compiles and links without any warnings:

 

    int pnl_hdl, word_doc, local_error, uilerror;

 

    pnl_hdl = LoadPanel (0, "main_panel.uir", TSTPANEL);
    DisplayPanel(pnl_hdl);
    local_error = Word_OpenDocument ("TestDoc.docx",
                                  pnl_hdl, "", 0, 0, &word_doc, &uilerror);

 

it returns error code -143 "Active X control error" and the document is not displayed.

 

What am I missing?

 

Thanks for any insights!

 

Tim

 

0 Kudos
Message 1 of 7
(3,324 Views)

Hi Tim,

 

Here is a link to a similar example using the Microsoft Excel Object Library to embed an excel spreadsheet into a CVI panel. The functions will be slightly different, but the general project structure will be very similar to embedding a Microsoft Word document. Do you see anything different between your simple project and how they have set things up in this example?

 

Embed Excel ActiveX Documents on a CVI Panel
http://www.ni.com/example/27580/en/ 

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 2 of 7
(3,283 Views)

Hi Adena,

Thank you so much for helping.  I looked at the example you mentioned.  Although it does embed a EXCEL file in a panel, it doesn't show how to open a pre-existing file, only how to create and edit a new one.  The functions it used are very different than the ones I was attempting to use.

 

It makes me wonder if I am using the activeX control incorrectly?  On my UIR panel I used create-> activex -> Microsoft Word document to create the new control. Then with the new control selected I used tools->Generate ActiveX Control Driver.  I accept all defaults and it creates MSWORD.h, MSWORD.c, MSWORD.fp, MSWORD.obj.  I then run the code I show in my first post.  Does that sound right?

 

I feel like I am somehow missing a reference to the ActiveX Control ID but can't find any example of how to use it to actually open a pre-existing doc.  Any insights you could provide would be greatly appreciated!

 

 

 

0 Kudos
Message 3 of 7
(3,272 Views)

Hi Tim,

 

Sorry for the misunderstanding! I didn't realize you were trying to load a pre-exisiting Microsoft Word file into an Active X control in CVI so that it is displayed on your UI. At what step are you specifying the path to the document that you would like to load? 

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 4 of 7
(3,260 Views)

Adena,

 

The direct answer to your question is in the code above, see the call to Word_OpenDocument "TestDoc.docx"

 

But your hint has helped. I had originally put my word doc in where I thought the working directory was so didn't think I needed full path to it.  When I added the fully qualified path it opened !   Here is the code snippet I have so far for anyone else needing an example:

 

    CA_InitActiveXThreadStyleForCurrentThread (0, COINIT_APARTMENTTHREADED);

    SetSleepPolicy (VAL_SLEEP_MORE);

    pnl_hdl = LoadPanel (0, "main_panel.uir", TSTPANEL);
    DisplayPanel(pnl_hdl);
    local_error = Word_OpenDocument ("C:\\WdDocTst\\Test.docx", pnl_hdl, "", 50, 50,

                                                               &word_doc, &uilerror);
    RunUserInterface ();

 

It is a poor display however, in that it covers the entire panel with an over-zoomed upper-left display of the doc only.  Obviously I need to massage the fit/sizing.  I tried:  

    
    GetObjHandleFromActiveXCtrl (pnl_hdl, TSTPANEL_DOCUMENT, &doc_hdl);
    local_error = Word_ZoomSetPercentage (doc_hdl, errinfo, 50.0); 

    CA_GetAutomationErrorString (local_error, msg, 1024);

 

It always returns "No such interface supported".  This same error is given for any other procedure that I try that is presented in the generated MSWORD.h.  I'm probably using it incorrect but the MSWORD.fp file that was generated is pretty much useless because if I click on any function name or parameter it says "Documentation for this function, if provided by the server, is located in the function help.", then for help: "Could not launch C:\Program Files (x86)\Microsoft Office\Office15\VBAWD10.CHM", so I have no idea what the functions are supposed to do or how to use the parameters.  Do you know where I can get the missing help file, or any documentation on how to use these functions?

 

Honestly one basic example of how to use a few of these interfaces would save me many hours.  I'm pretty close to giving up 😞

0 Kudos
Message 5 of 7
(3,230 Views)

Hi Tim,

 

I'm glad you were able to get it to show up! I've been trying to look and I don't think we have any examples that open up a pre-existing Microsoft Word file. 

 

It sounds like you're missing the Microsoft Word Visual Basic help documentation. I think I was able to find it online but I was having a problem with my viewer and wasn't able to get it to open up on my computer. Does this help documentation look like what you're missing?

 

https://www.microsoft.com/en-us/download/confirmation.aspx?id=40326

 

I'll keep asking around to make sure we don't have any examples that I may have missed!

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 6 of 7
(3,198 Views)

Hi Adena,

 

I downloaded and installed the VBA help documentation.  I couldn't get it to display either but searched my PC and found the 'VBAWD10.chm' file in 'C:\Program Files\Microsoft Office\Office15'.  I moved a copy into 'C:\Program Files (x86)\Microsoft Office\Office15' where it was expected to exist, and now it opens. 

 

But this is a help file for Visual Basic programming and has nothing to do with the ActiveX Microsoft Word Document library that the NI ActiveX Wizard uses. 

 

A shame such an extensive looking library exists but no way to understand how to use it!

Thanks for trying to help anyway.

Message 7 of 7
(3,188 Views)