Results 1 to 7 of 7

Thread: How to close a Word Document with API

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Posts
    16

    Post

    I,
    How can i close a word document with API like 'PostMessage' or other, without close Microsoft Word?

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Posts
    16

    Post

    Thanks, it works.
    Just one more thing, using the ShellExecute how can i find the hwnd of the application i have launch.

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Here is an easier way, it does not use the API:

    Add a reference to Microsoft Word 8/9.0 object library

    Code:
        Dim wd As Word.Application
        
        'get object
        Set wd = GetObject(, "Word.Application")
        
        If wd Is Nothing Then
            'error
            MsgBox "Can't Find WORD!!!"
        Else
            'close document
            wd.ActiveDocument.Close False
        End If
    Tom

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Posts
    16

    Post

    Thanks, but that way i now how to do.
    I making an application that start the default application of a file. And for word i want to leave to word application open, i want just to close the document.
    It's possible using the API?
    Can someone help me or where can i found this type of information.

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    My code finds the existing instance of MS Word and closes the active document, while leaving Word open. Is that not what you wanted?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Posts
    16

    Post

    Yes, but, if i want to do the same for Excel i need another routine to treat that.
    And i don't want that, I want with a simple routine treat word, excel... all office applications.
    Thanks,

  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    You would probably have to use FindWindow, then EnumChildWindows, then sendmessage WM_CLOSE to the child windows.....that may not take care of the "SAVE DOCUMENT?" dialogs though....

Posting Permissions

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



Click Here to Expand Forum to Full Width