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?
Printable View
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?
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
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