2 UserForms 1 Outlook Session

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
141
Outlook 2016
In my Outlook VBA I have "ThisOutlookSession". This contains a code for when I create a new email or are replying to an email, a button is on the ribbon that when clicked brings up UserForm1.

I have now created UserForm2 but don't know how to activate/load/show it. However I don't need it to be only usable when replying or creating a new email.

I need these 2 userforms to operate individually. if it makes sense.

This is my code for the project:
VBA Code:
Option Explicit


Sub Client_ID()
Dim wdDoc As Object
Dim oRng As Object
Dim oBM As Object
Dim oFrm As UserForm1
Dim strText As String
    On Error GoTo Err_Handler
    If TypeName(ActiveWindow) = "Inspector" Then
        If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
            Set wdDoc = ActiveInspector.WordEditor
            On Error Resume Next
            Set oBM = wdDoc.bookmarks("_MailAutoSig")
            If Not oBM Is Nothing Then
                Set oRng = oBM.Range
                oRng.Start = oRng.Start + 2
                oRng.collapse 1
            Else
                Set oRng = wdDoc.Range
                oRng.collapse 1
            End If
            On Error GoTo Err_Handler
            Set oFrm = New UserForm1
            With oFrm
                .Show
                If .Tag = 0 Then GoTo lbl_Exit
                strText = vbCr & "=================================================================" & " " & vbCr & _
                          "The following information is for HIA/GK internal use and can be ignored." & " " & vbCr & _
                          "File ID:_       " & .TextBox1.Text & vbCr & _
                          "Type_PL:_    " & .ComboBox1.Text & vbCr & _
                          "Type_CL:_    " & .ComboBox2.Text & vbCr & _
                          "Drawer:_     " & .ComboBox3.Text & vbCr & _
                          "POL:_           " & .TextBox2.Text & vbCr & _
                          "================================================================="
                Unload oFrm
            End With
            oRng.Text = strText
            oRng.Start = wdDoc.Range.Start
            oRng.collapse 1
            oRng.Select
        Else
            GoTo Err_Handler
        End If
    Else
        GoTo Err_Handler
    End If
lbl_Exit:
    Set wdDoc = Nothing
    Set oRng = Nothing
    Set oBM = Nothing
    Set oFrm = Nothing
    Exit Sub
Err_Handler:
    Beep
    Resume lbl_Exit
End Sub

Any help would be greatly appreciated.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top