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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I Reposition a VBA Form in Word?

Status
Not open for further replies.

cheriberi

Technical User
May 27, 2003
60
US
Is it possible to set up a form in Word VBA so that when the form pops up, it is over to the right of the screen, allowing users to see a bit more of what is on their page before making their selections on the form?

Thanks!
 
You can set the Left and Top properties of the userform. This can be done on initializing of the form, or done programmatically by user action (i.e. you can move the form out of the way by some user action), or done programmatically based on some internal logic/event.

You could also make the form shrink to a wee little thing while the user looks at the document, then they could click it back to full size. If you do not make the form modal, then they could simply move it around themselves.

Lots of options.



Gerry
 
What I want to do is allow the form to stay on screen while the user possibly repositions the cursor or does some editing. Is that possible?

And just out of curiosity, how do you make the form really tiny and then big again?

Cheryl [ponder]
 
Make the ShowModal property of the UserForm = False. This allows the focus to be moved to the document. The user can move around and edit.

To resize, what I do is have a Label across the top of the form, The caption is "Shrink / Expand". On the Label_Click event I put position and sizing instructions.
Say the fully open form is: Height = 130, Width = 300, Top = 200, Left = 200. The following toggles between fully displayed, and shrunk and moved to the top of the screen.

Sub Label_Click ()
If Me.Height = 130 Then
With Me ' shrink form and place at top of screen
.Height = 22
.Width = 100
.Top = 0
.Left = 250
End With
Else
With Me ' expand form to position
.Height = 130
.Width = 300
.Top = 200
.Left = 200
End With
End If
End Sub

Just make sure you keep enough of the actual form visible in the smaller size! It is possible using API to have a click title bar event, but there is no easy way in VBA. Clicking the title bar will not fire the resizing event. At least a small part of the form has to be visible - in that part is my label, so it can be clicked.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top