I am fairly new to VBA - I apologize for the naive question. I've created a
macro in word that opens a userform and minimizes Word. The problem is that
when Word minimizes, the userform is no longer the focus and "falls" behind
any other open windows.

How do I minimize Word and place the focus on the form I just opened? Below
is the code in Word I'm using.

Sub Procedure()

Load UserForm

For Each myTask In Tasks
If InStr(myTask.Name, "Microsoft Word") > 0 Then
myTask.Activate
myTask.WindowState = wdWindowStateMinimize
End If
Next myTask

UserForm.Show

End Sub

In the ideal world I would prefer to have a stand alone application and
never open Word, or if it opens, minimize/hide it immediately. All the
functionality is built into the form. When I have the time to dedicate to
it, I will migrate the code to VB. Does anyone have any tips to minimize the
visibility of Word in this scenario? (No pun intended).

Thanks,
John

RE: Set Focus on Form & Minimize Word by Martin

Martin
Thu Mar 16 08:53:27 CST 2006

Just a thought but do you need the Load UserForm line? UserForm.Show is
usually sufficient to load the form and it happens after you've looped
through your tasks.

"RedDirt" wrote:

> I am fairly new to VBA - I apologize for the naive question. I've created a
> macro in word that opens a userform and minimizes Word. The problem is that
> when Word minimizes, the userform is no longer the focus and "falls" behind
> any other open windows.
>
> How do I minimize Word and place the focus on the form I just opened? Below
> is the code in Word I'm using.
>
> Sub Procedure()
>
> Load UserForm
>
> For Each myTask In Tasks
> If InStr(myTask.Name, "Microsoft Word") > 0 Then
> myTask.Activate
> myTask.WindowState = wdWindowStateMinimize
> End If
> Next myTask
>
> UserForm.Show
>
> End Sub
>
> In the ideal world I would prefer to have a stand alone application and
> never open Word, or if it opens, minimize/hide it immediately. All the
> functionality is built into the form. When I have the time to dedicate to
> it, I will migrate the code to VB. Does anyone have any tips to minimize the
> visibility of Word in this scenario? (No pun intended).
>
> Thanks,
> John

RE: Set Focus on Form & Minimize Word by RobertPaulsen

RobertPaulsen
Thu Mar 16 08:58:29 CST 2006

Setting the user form to a modeless state worked for me (also the tasks code
can be simplified.

Try this:

Load UserForm1
Application.WindowState = wdWindowStateMinimize
UserForm1.Show 0


"RedDirt" wrote:

> I am fairly new to VBA - I apologize for the naive question. I've created a
> macro in word that opens a userform and minimizes Word. The problem is that
> when Word minimizes, the userform is no longer the focus and "falls" behind
> any other open windows.
>
> How do I minimize Word and place the focus on the form I just opened? Below
> is the code in Word I'm using.
>
> Sub Procedure()
>
> Load UserForm
>
> For Each myTask In Tasks
> If InStr(myTask.Name, "Microsoft Word") > 0 Then
> myTask.Activate
> myTask.WindowState = wdWindowStateMinimize
> End If
> Next myTask
>
> UserForm.Show
>
> End Sub
>
> In the ideal world I would prefer to have a stand alone application and
> never open Word, or if it opens, minimize/hide it immediately. All the
> functionality is built into the form. When I have the time to dedicate to
> it, I will migrate the code to VB. Does anyone have any tips to minimize the
> visibility of Word in this scenario? (No pun intended).
>
> Thanks,
> John

RE: Set Focus on Form & Minimize Word by RobertPaulsen

RobertPaulsen
Thu Mar 16 09:03:30 CST 2006

Setting the form's state to modeless worked for me. Also, the tasks code is
unnecessary to minimize Word. Try this:

Application.WindowState = wdWindowStateMinimize
UserForm1.Show 0


"RedDirt" wrote:

> I am fairly new to VBA - I apologize for the naive question. I've created a
> macro in word that opens a userform and minimizes Word. The problem is that
> when Word minimizes, the userform is no longer the focus and "falls" behind
> any other open windows.
>
> How do I minimize Word and place the focus on the form I just opened? Below
> is the code in Word I'm using.
>
> Sub Procedure()
>
> Load UserForm
>
> For Each myTask In Tasks
> If InStr(myTask.Name, "Microsoft Word") > 0 Then
> myTask.Activate
> myTask.WindowState = wdWindowStateMinimize
> End If
> Next myTask
>
> UserForm.Show
>
> End Sub
>
> In the ideal world I would prefer to have a stand alone application and
> never open Word, or if it opens, minimize/hide it immediately. All the
> functionality is built into the form. When I have the time to dedicate to
> it, I will migrate the code to VB. Does anyone have any tips to minimize the
> visibility of Word in this scenario? (No pun intended).
>
> Thanks,
> John