Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch to application (Word)

Status
Not open for further replies.
Oct 5, 1999
105
GB
I have a VB6 prog that creates a new word document. Then I want the Word doc to be on top for the user to use.

I can easily create the document, but am not sure how to get Word on top. I'm sure it's very easy and has been covered before, but I'm not sure what to search the forum for!

Sample code:
Code:
Private Sub Command1_Click()

Dim appWord As Word.Application
Dim docWord As Word.Document
    
    On Error Resume Next
    Set appWord = GetObject(, "Word.Application")       ' find Word if open
    On Error GoTo 0
    If Err Then
        Set appWord = CreateObject("Word.Application")  ' if not then open it
    End If
    appWord.Visible = True
    Set docWord = New Word.Document                     ' start new document
    Debug.Print "Created;"; docWord.Name
    ' make the document
    docWord.Content.InsertAfter Text:="Here is your document."
    'etc
    'etc
    
    Set docWord = Nothing
    Set appWord = Nothing

End Sub

How do I then get the Word window on top


 

I usually have:
[tt]appWord.Visible = True[/tt]
as last statement (well, before setting it to Nothing) and this sets it on top of any other app I have open - like my VB6 app.

Have fun.

---- Andy
 
You can make any one your forms 'really' on top of any other application using the SetWindowPos function.

Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Statement after loading Word:-
ReturnValue = SetWindowPos(MyForm.hWnd, -1, 0, 0, 0, 0, 1)

I can't remember how but if you can get the hWnd of your Word app I this might also work for it.

There were various posts on getting hWnds of applications some time ago.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top