What is the syntax to open a userform in the top-right screen corner?

 Me.StartUpPosition = 0
 Me.Top = Application.Top + 25
 Me.Left = Application.Left + Application.Width - Me.Width - 25
'example - place in UserForm_Activate procedure
Private Sub UserForm_Activate() 'when form opens
   Me.StartUpPosition = 0
   Me.Top = Application.Top + 25
   Me.Left = Application.Left + Application.Width - Me.Width - 25
End Sub

 

Advertisements

What is the syntax to prevent closing userform using X Corner

Insert this code into userform code just like you would any procedure:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
   If CloseMode=0 Then
      Cancel=true
      MsgBox “Please use the exit button instead”, vbCritical
   End If
End Sub