Consulting

Results 1 to 1 of 1

Thread: Center UserForm in window

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Center UserForm in window

    I added a button to the ribbon of a new email window that when clicked brings up a UserForm. I would like for the UserForm to open up in the center of the new email window as opposed to right now that it just opens up at random places of my 3 screens. Below is the code that I have so far. Thanks in advance.
    Sub Add_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
    Last edited by Kulguy915; 10-15-2019 at 11:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •