Search code examples
excelvbauserform

VBA - Getting back to Macros from userform


I have a macro that at a certain part shows a userform, I publicly dimmed some variables in the userform in order to use it in the main macros.

Now I want to get back to the main macros after I hit "Proceed!" commandbutton.

Batch Divider

Here is my main macros:

Public C1 As String, C2 As String, C3 As String, C4 As String, C5 As String, C6 As String, C7 As String, C8 As String, C9 As String, C10 As String, C11 As String, C12 As String, C13 As String
Public NumB As Integer, NumofLines As Integer, Q1 As Integer, Q2 As Integer, Q3 As Integer, Q4 As Integer
Public Total As Double, Batch1Total As Double, Batch2Total As Double, Batch3Total As Double, Batch4Total As Double, Batch5Total As Double

Sub priority_calculation()

*Some code ....*

BatchDivider.Show

*Want to continue after hitting Proceed! commandbutton*


End Sub

Solution

  • Calling the form:

    Sub Tester()
        Dim frm As New BatchDivider 'create an instance of the form
        
        frm.Show       'show the form instance: code stop here until form is hidden/unloaded
        Debug.Print frm.MyGlobal    'read the global from the (now hidden) form instance
        Unload frm    'now done with the form....
    End Sub
    

    In the form:

    Public MyGlobal As String
    
    Private Sub CommandButton1_Click()
        MyGlobal = "value from form"
        Me.Hide   'not unload
    End Sub