Modeless form that still pauses code execution

前端 未结 3 1306
遥遥无期
遥遥无期 2020-12-06 14:22

Is there anyway to have a userform that acts modeless, while still pausing code execution like a modal form?

I\'d like the userform to show, but still allow interact

3条回答
  •  隐瞒了意图╮
    2020-12-06 14:39

    The Best method would be to use two different subs. I was able to solve this problem without splitting my sub as follows:

    Public Mode as Boolean
    
    Sub Stuff()
        If Mode Then
            Goto Continue
        End If
    
        'Code before Userform
    
        Mode = True
        Userform.Show vbModeless
        Exit Sub
    
    Continue:
        Mode = False
    
       'Rest of your code
    
    End Sub
    

    I made "Mode" a global variable because I use this userform for multiple subs. If you are using a single sub you can use it locally. I also made "Mode" false when opening this workbook by going under "ThisWorkbook" Tab and adding the following code:

    Private Sub Workbook_Open()
        Mode = False
    End Sub
    

    This again will only be needed if you use your userform for more than one sub. Last add this code under your Userform code when your proceed button is pressed.

    Private Sub Confirm_Click()
        Userform.hide
        if Mode Then
            Call Stuff
        End If 
    End Sub
    

    If you are only are using the one sub method skip the if statement and just call the sub.

提交回复
热议问题