Я предполагаю, что кнопка Command находится на одной пользовательской форме, а элемент управления календаря - на другой.
Вы не говорите, какую версию VBA вы используете.Я проверил это в Excel 2003. Я знаю, что лучшие решения доступны, например, в VB 2010.
Подход 1
Вам нужна вторая форма?Вы можете скрыть элемент управления с помощью:
ControlName.Visible = False
и сделать его видимым с помощью
ControlName.Visible = True
Подход 2
Вам нужны некоторые открытые переменные вмодуль:
Public ButLeft As Integer
Public ButHeight As Integer
Public ButTop As Integer
Public Form1Left As Integer
Public Form1Top As Integer
В событии щелчка для командной кнопки укажите:
' This stores information about the current position of
' Form 1 relative to the active window.
With Me
Form1Top = .Top
Form1Left = .Left
End With
' This stores information about the current position of the
' command button relative to the useable part of Form 1.
With Me.CommandButton
ButTop = .Top
ButLeft = .Left
ButLeft = .Height
End With
В форме 2 укажите:
Private Sub UserForm_Activate()
' This positions Form 2 relative to the current position
' of the command button. The "+50" is because the stored
' values do not allow for the width of Form1's border.
' Experiment to get values that look good to you.
With Me
.Top = FormTop + But1Top + But1Height + 50
.Left = FormLeft + But1Left + 50
End With
End Sub
С этим кодомФорма 2 отображается под кнопкой команды независимо от того, как пользователь перемещает форму 1.