Excel VBA - positioning an Userform

Luca Tramontana 21 Reputation points
2023-10-03T15:04:14.6866667+00:00

Dear All,

by the below Excel VBA code I move an Userform below a TextBox:Pos_01

Dim FormTitleSize As Double
Dim dblTop As Double
Dim dblLeft As Double
With Me
    FormBorderSize = (.Width - .InsideWidth)
    FormTitleSize = .Height - (.InsideHeight + FormBorderSize)
    dblTop = .Top + .txtID_Request.Top + .Height - .InsideHeight + FormTitleSize
    dblLeft = .Left + txtID_Request.Left + .Width - .InsideWidth - FormBorderSize
End With
With frmList
    .StartUpPosition = 0
    .Top = dblTop
    .Left = dblLeft
End With

but I would like to have the Userform aligned with the button indicated by the red arrow as below image:

Pos_02

Any suggestion?

Thanks

Microsoft 365 and Office Development Other
Microsoft 365 and Office Excel For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2023-10-04T08:59:57.1933333+00:00

    Check this expression:

    dblLeft = .Left + myButton.Left + myButton.Width + FormBorderSize - frmList.Width
    

    The form should be repositioned when some parts are invisible (off-screen).

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.