Stupid_Intern
Stupid_Intern

Reputation: 3460

Position two userform with no space between them

How can I adjust the userforms positions inorder to place them side by side when Intialized i.e. remove the space between them.

enter image description here

From the answer I tried this but it doesn't work

CIF.Show
With CIF
    .Top = Application.Top + 5
    .Left = Application.Left + 10
End With

Instructions.Show
With Instructions
    .Top = Application.Top + 5
    .Left = CIF.Left + CIF.Width
End With

Upvotes: 0

Views: 397

Answers (3)

Sgdva
Sgdva

Reputation: 2800

Does this work?

Sub test()
With CIF
.Show vbModeless
.Left = .Left - .Width / 2
End With
With Instructions
.Show vbModeless
.Left = .Left - .Width / 2
End With
Unload CIF
Unload Instructions
End sub

enter image description here

UPDATED:
To avoid overlap
Seems like there's a constant value 7 among the close button and the border of the userform. Following should address it (doesn't matter userform size).

Sub test()
With CIF
.Show vbModeless
.Left = .Left - .Width / 2
End With
With Instructions
.Show vbModeless
.Left = CIF.Left + CIF.Width + 7
End With
Unload CIF
Unload Instructions

enter image description here

Upvotes: 2

RGA
RGA

Reputation: 2607

You need to change the StartUpPosition property to Manual (value = 0, I believe). Then, you can adjust the top and left placement to remove the gap

Upvotes: 1

gizlmo
gizlmo

Reputation: 1922

Set the Left option of the second form to the Left of the first form + Width of the first one

UserForm2.Left = UserForm1.Left + UserForm1.Width

On Windows 7 i had to add another 7 pixels, so like this:

UserForm2.Left = UserForm1.Left + UserForm1.Width + 7

You might have to modify this depending on the OS

Upvotes: 1

Related Questions