Set Focus on Form & Minimize Word

R

RedDirt

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
 
M

Martin

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.
 
R

Robert Paulsen

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
 
R

Robert Paulsen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top