LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot create new Word document !!!!!!

Hi All,
 
We recently migrated both to WinXP and CVI7.0
 
Problem is - my application activates both MS Word and Excel, and then attempts to create new documents, plus writing to them
 
Opening Word (& Excel) was successful, but I COULD NOT CREATE A NEW WORD DOCUMENT (the Excel document was okay)
 
I get an error message. Now, BEFORE, this worked fine (on Win98). 
[I as using word2000.c, and wordreport.c]
 
I've been trying to solve this issue for months, so pleeeeeeeeeeease help !
 
Thanx!
---Jojo M.

Message Edited by Jojo9999 on 07-20-2005 05:36 AM

0 Kudos
Message 1 of 20
(4,858 Views)

Jojo,

The source of your problem might be that when you migrated to XP your versions of MSOffice also were upgraded.  Typically if you are using a COM interface for an older version of something (i.e. you are using a word2000 interface and you now have word2002) it shouldn't be a problem.  Obviously it's good programming practice to include backwards compatability, but we are talking about the company who designed WindowsME here :-).

There are two things you can do to see if this is the problem.

1.) you can install word 2000 along with any newer version of word you have on your machine, which should provide you with the correct COM interface

2.) you can build a new COM interface using the .DLL that the newere version of word provides you with.  Unfortunatly with this method you might need to do a lot of code maintenance because it's not a guarantee that the function calls are going to be the same names/formats.

Message 2 of 20
(4,841 Views)

Dave,

First of all, thank you very much for you reply.

I will try the first option you suggested.

Regarding the second option - how do I build a new COM interface? Acrutally, I don't even understand how to use the .fp files - (the person who worked with this program before me is now unreachable).

Would it be possible to construct the object database again? (using the newer version of CVI) I tried this once, but I don't remember how I did it...

Thanx again!

---JOJO

0 Kudos
Message 3 of 20
(4,832 Views)

Jojo,

Constructing the object database again is analagous to building a new COM interface, and the answer is yes, you can do this.  The way you do this is by going to Tools->Create ActiveX Controller.

Click the 'Next' button on the intial screen and you will see a huge list of ActiveX servers.  Scroll down and select the ActiveX server that you want.  In this case I would say it might be the 'Microsoft Word 10.0 Object Library'. 

As far as using the .fp files.  In my experience with using ActiveX controls that are auto-generated by CVI the .fp files aren't all that useful for anything other than actually condensing the functions into a managable/categorized list.  If you need any kind of documentation on the functions you will probably be best served by using MSDN.

Message 4 of 20
(4,827 Views)

Hi, Dave

I uninstalled office 2003, and installed office 2000 instead, but the situation is pretty much the same-  I can open both word and excel, create an excel document, but NOT a word document.

From your reply I gather, that re-building the function database is difficult, so I'd really like to get to the bottom of the first solution before.

Is there anything else I can do (together with re-installing Office) to make it okay? Is there any way I can know the source of my problem?

I tried debbuging the application - the function call that generates a new word document returns an error , and since this is a hidden function, the program jumps immedietaly to the error handling code. Perhaps there is a way to tell the exact problem that you are aware of?

Thanx again!

J.M

0 Kudos
Message 5 of 20
(4,807 Views)
Hi Jojo,
 
To answer your first question, re-building the function database isn't very difficult at all, the problem is that with different versions of word on the 2 machines you might not build the same database and you might have to change around a lot of your code.  But the good news is that it doesn't seem to me that the problem is the functions within the COM object.
 
To answer your second question, there is a way to get a text message of the error that you are receiving.  Check out the CA_GetAutomationErrorString function. 
 
I have a decent amount of experience with various ActiveX controls and ActiveX integration but unfortunatly I have never used MS Word activex.  But I will give you my best guess as to what your problem might be. 
After a quick build of a word ActiveX ctrl I'm assuming that the object model for Word is something like the following (for the three highest level applications)  Application->Documents->Document.  I would say that you are having a disconnect somewhere between when you get your application handle and when you pass it to your documents function.  If this is the case, you would probably be unsuccessful at not only creating new word documents, but also manipulating any word document that was already created and opened.   To find out if this is the case try to load a word document that is already created and see if you can write to it using your ActiveX functions.  Let me know if that is successful and we can work from there.
Message 6 of 20
(4,777 Views)

Hi Dave,

Yes, as I expected - you were right. I cannot even open an existing document.

I get the same error string when I print the string using the function you gave me, but it's not extremely useful: "An exception has occurred"... (this happens for both New and Open).

Here is the New function:

HRESULT CVIFUNC WordRpt_DocumentNew(CAObjHandle appHandle, char template[], CAObjHandle *docHandle)
{
    HRESULT error = S_OK;
    CAObjHandle docsHandleL = 0;
    CAObjHandle docHandleL = 0;
    BSTR Bstr;
      
    if (!appHandle)
        errChk(E_INVALIDARG);
       
    if (!docHandle)
        errChk(E_INVALIDARG);
   
    errChk (Word_GetProperty (appHandle, NULL, Word_ApplicationDocuments,
                   CAVT_OBJHANDLE, &docsHandleL));      
              
    errChk(CA_CStringToBSTR (template, &Bstr));
   
    errChk (Word_DocumentsAddOld (docsHandleL, NULL, CA_VariantBSTR (Bstr), CA_DEFAULT_VAL,
                                  &docHandleL));

Error:

    if (!FAILED(error))
        *docHandle = docHandleL;
        
    if (docsHandleL)
        CA_DiscardObjHandle(docsHandleL);
       
    return error;                                                 
 }     

The error occurs at:    Word_DocumentsAddOld

What do you think may be causing it? If the problem is with the handle, how can I fix it?

Thanx again!

---Jojo

 

0 Kudos
Message 7 of 20
(4,759 Views)

Jojo,

My thought is that the docsHandleL that is being returned by the Word_GetProperty function isn't a valid handle.  I would try using Word_ApplicationGetDocuments function instead. 

If this doesn't work, then we have to assume that the appHandle isn't valid.  It looks as if you are getting the appHandle from a callback on the WordRpt functions that is called when a new document is created?  If this is so, try using the Word_ActiveApplication function to get the application handle and see if that works.

0 Kudos
Message 8 of 20
(4,750 Views)

Hi Dave,

Indeed, the handle returned by Word_ActiveApplication is different from the one I had (which was retunred by a previous call to Word_NewApplication and passed between the functions). But still, even with the new handle I get the same error.

Regarding Word_ApplicationGetDocuments, something strange occured - the first time I wrote this funciton's name, I found it in the file, but didn't get a chance to use it before it vanished! couldn't find it anywhere, and it was no longer known to the compiler. What could have happened?

Anyway, I'm stuck again and could REALLY use your help.

Thanx!

---Jojo

0 Kudos
Message 9 of 20
(4,677 Views)

Hi Jojo,

Quite ironically I recently had a problem in Excel similar to what you had in Word.  I was using the Excel2000.c, Excel2000.fp file and I could open the application but not create a new document or open an existing document.  The problem was that I am running Excel2002 and I had created a couple of files in Excel2002.  The controller works fine when loading Files that were created with Excel 2000 or lower, but anything created with a newer version of excel would not work.  Likewise, I couldn't create an altogether new document in Excel.

I was able to fix this by building a new Excel ActiveX controller (specifically the Excel 10.0 object library), and using the functions in there.  So if you are still having problems with Word, here is what I would do if I were you (this should fix the Word_ApplicationGetDocuments error as well ).

1.)  Go to Tools->Create ActiveX Controller

2.) At the list of controllers, select the 'Microsoft Word 10.0 Object Library'. And click next to build it.

3. ) CVI will build the controller for you automatically, and it should also add it to your project.  From here, you will need to use the functions in the 10.0 Object Librar

a.)  I haven't used the word library, but in Excel there are some subtle differences and I'd imagine they are similar in word.  Specifically you probably won't be able to use Word_GetProperty anymore.  However adding this object library will bring back the Word_ApplicationGetDocuments function for you.

b.) Instead you will do something like the following in your code:

********************************************************************************

Word_NewApplication (NULL, 1, LOCALE_NEUTRAL, 0, &WordApp); //Open a new instance of word

Word_ApplicationGetDocuments (WordApp, NULL, &WordDocuments); //Get the documents container

Word_DocumentsOpen (WordDocuments, NULL, FileName, CA_DEFAULT_VAL,  //Open the word document containted in "FileName"
                    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, &ThisDocument);

********************************************************************************

4.) One other caveat I have found is that 'FileName' (the name of the file you wish to open ) must be an absolute path, if it's relative you will get an error.
 
Try this, let me know how it works ( I know it's a lot of stuff in one post so if there is anything missing let me know) .  And if you still have problems repost and we can see what else we can do.
Message 10 of 20
(4,661 Views)