I have created a user form with a list box.
When I double click a line in the listbox it opens a word document, but the
fpcus is not on the new document...
I want the document that opens to be the activedocument.
Here is the code....
Can someone tell me what I'm doing wrong?
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
Dim i As Long
' Items are indexed from zero
' Loop through all the items..
For i = 0 To ListBox1.ListCount - 1
'..and check whether each is selected
If ListBox1.Selected(i) Then
' If selected, display item in msgbox
Dim LWordDoc As String
Dim oApp As Object
'Path to the word document
LWordDoc = "C:\Documents and Settings\iris\My Documents\" &
ListBox1.Column(0, i) & " " & ListBox1.Column(1, i) & ".doc"
If Dir(LWordDoc) = "" Then
MsgBox "Document not found."
Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True
'Open the Document
oApp.Documents.Open FileName:=LWordDoc
End If
thank you
iris
Unload Me
'UserForm6.cmbTermSearchHeb.Text = ListBox1.Column(5, i)
'UserForm6.cmbTermSearchEng.Text = ListBox1.Column(3, i)
'Unload UserForm16
'UserForm6.Show vbModeless
End If
Next i
End Sub
I would declare a document object
Dim mydoc as Document
and then use
Set mydoc = oApp.Documents.Open(FileName:=LWordDoc)
and then do activate it, use
mydoc.Activate
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"iris" <ir...@discussions.microsoft.com> wrote in message
news:55B5450D-EA48-4010...@microsoft.com...