Results 1 to 3 of 3

Thread: Enumerating thru all Word Docs using GetObject?

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Enumerating thru all Word Docs using GetObject?

    Can i do this, or how can i list all the open word documents (apps) and then allow the user to choose a word document which he wants to insert to, then gain control of that instance of word using GetObject?

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Create a form and place a commandbutton and listbox on it. Add the follwing. Make sure to reference Word 8 or 9.

    Dim wo As Word.Application
    Dim wds As Word.Documents
    Dim wd As Word.Document

    Private Sub Command1_Click()

    ' list all open documents
    On Error Resume Next

    Set wo = GetObject(, "Word.Application")

    If CStr(wo.Documents.Count) <> 0 Then
    Set wds = wo.Documents
    For Each wd In wds
    List1.AddItem wd.FullName
    Next
    Else
    MsgBox "No documents open"
    End If

    End Sub

    Private Sub Form_UnLoad(Cancel As Integer)
    Set wo = Nothing
    Set wds = Nothing
    Set wd = Nothing
    End Sub

    Private Sub List1_Click()
    Dim wws As Word.Windows
    Dim ww As Word.Window

    Set wws = Word.Windows

    For Each ww In wws
    If ww.Document.FullName = List1.List(List1.ListIndex) Then
    ww.WindowState = wdWindowStateMaximize
    End If
    Next
    Set wws = Nothing
    Set ww = Nothing
    End Sub
    --------------

    HTH
    John

  3. #3
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Put ww.Visible = True after ww.WindowState = wdWindowStateMaximize to show it.


    And the reason I used one object to load the documents and another to make visible is because I couldn't figure out a way to make the objects in the commanbutton event work with WindowState.

    If you do, let me know.

    [email protected]

    Thanks,
    John

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