none
How to prevent dragging userform? RRS feed

  • Question

  • I would like to know how to prevent dragging a Userform in MS Excel workbook VBA project.
    • Moved by Neda Zhang Monday, November 14, 2016 5:26 AM Moved from vb forum
    Sunday, November 13, 2016 7:43 AM

All replies

  • you have probably 100% more chance on an answer in the Excel developers forum for this question

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev

    This forum is for the program language VB (versions not older than VB7)


    Success
    Cor

    • Proposed as answer by IronRazerz Sunday, November 13, 2016 1:05 PM
    Sunday, November 13, 2016 8:34 AM
  • Hi Athula61,

    Thank you for posting in MSDN Forum.

    Since your issue seems more related to the product feature of Excel, I will move this thread to the more related forum for better support.

    Please refer: https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev

    Thanks for your understanding and support.

    Best Regards,

    Neda Zhang 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    • Edited by Neda Zhang Monday, November 14, 2016 5:25 AM
    Monday, November 14, 2016 5:23 AM
  • Hi Athula61,

    use the code mentioned below.

    it will prevent the user from dragging the User Form.

    Option Explicit
    
    Private Type Position
     Left As Single
     Top As Single
    End Type
    
    Private Sub UserForm_Layout()
         Static Pos As Position
    
         Dim Mvd As Boolean
         
         'If the form is just being initialized, store the position
         If Pos.Left = 0 Or Pos.Top = 0 Then
             Pos.Left = Me.Left
             Pos.Top = Me.Top
             Exit Sub
         End If
         
         'Check to see if the form has been moved
         Mvd = False
         If Me.Left <> Pos.Left Then
             Me.Left = Pos.Left
             Mvd = True
         End If
         If Me.Top <> Pos.Top Then
             Me.Top = Pos.Top
             Mvd = True
         End If
         
         If Mvd Then
             MsgBox "Please don't move me !", vbCritical
         End If
    End Sub
     
    

    Reference taken from the link mentioned below.

    Locking a userform position

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 15, 2016 2:08 AM
    Moderator
  • Hi Athula61,

    after posting the issue till today you did not respond to any of the suggestion.

    if your issue is solved then let us know about that so that we can close this thread.

    if your issue is still exist then I already posted a solution for your issue.

    please refer that suggestion.

    if you think that the suggestion given by me can solve your issue then mark it as an Answer.

    if then also you need further help then let us know about that.

    Regards

    Deepak 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 22, 2016 7:39 AM
    Moderator