Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Sep 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Closing word docs manually vs programatically (2000)

    Hello

    I have an application that opens a word document.
    The user can close it manually (clicking on the upper right cross)

    My application when closing is looking for any opened documents
    If a document is opened, it closes it like this (C++):

    for(int i=1; i<=FWord->Documents->Count; i++)
    FWord->Documents->Item((OleVariant)i)->Close(&TVariant(false));

    I get an error by the mere fact of trying to access the Count member.
    How else can I check if documents are left open ?
    Or can I prevent the user from closing the file manually (this I doubt) ?

    Thanks

    NB Thanks for all the previous answer to my other posts

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Closing word docs manually vs programatically (2000)

    I don't know C++, but in general, when trying to do something like this, you must loop backwards from Count to 1. The reason for this is that closing a document changes the count of open documents.

  3. #3
    New Lounger
    Join Date
    Sep 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing word docs manually vs programatically (2000)

    I see.
    something like
    while(FWord->Documents->Count)
    FWord->Documents->Item(1)->Close(&TVariant(false));

    However in my case, the mere fact of doing something like
    int count = FWord->Document->Count
    causes an error !

    I just hope it is not a bug in the OLE object I am using to automate Word

    Tigrane

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Closing word docs manually vs programatically (2000)

    Is FWord (presumably a reference to an application object) still valid when you run this code? I'm not sure from your first post exactly what the problem scenario is, but if the user has closed the instance of Word you are automating, possibly not.

    (In your latter example, Document should be Documents, but I doubt this is your problem.)

  5. #5
    New Lounger
    Join Date
    Sep 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing word docs manually vs programatically (2000)

    You are right.
    I found out that the porblem was exactly that, FWord is not valid anymore.
    I have now an event that notifies me when FWord is about to quit

    Cheers

    Tigrane

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •