As this is unlikely to be used in every message you create, you should add a button to the Message ribbon to call the following macro when you have a message open for editing. This will call a userform - here UserFormName - and write the data from that form to the open message immediately before the signature block (or if there is no default signature, to the start of the message). You can change the names of the userform and the controls as required. I have coded only two text boxes, but you can add as many as you require and modify the strText text string as appropriate.
Option Explicit
'Graham Mayor - https://www.gmayor.com - Last updated - 28 Sep 2019
Sub Add_Client_ID()
Dim wdDoc As Object
Dim oRng As Object
Dim oBM As Object
Dim oFrm As UserFormName
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 - 1
oRng.collapse 1
Else
Set oRng = wdDoc.Range
oRng.collapse 1
End If
On Error GoTo Err_Handler
Set oFrm = New UserFormName
With oFrm
.Show
If .Tag = 0 Then GoTo lbl_Exit
strText = vbCr & "File ID: " & .TextBox1.Text & vbCr & _
"Customer #: " & .TextBox2.Text & vbCr & _
"etc"
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
The userform can have as many text boxes as you need and two buttons. The code for the userform would be as follows. Change the button names as appropriate. The first is obviously the OK button, the other the cancel button. All the text boxes are validated for content.
Option Explicit
Private Sub CommandButton1_Click()
Dim oCtrl As Control
For Each oCtrl In Controls
If TypeName(oCtrl) = "TextBox" Then
If oCtrl.Text = "" Then
MsgBox "Complete TextBox"
Beep
oCtrl.SetFocus
Exit Sub
End If
End If
Next oCtrl
Tag = 1
Hide
End Sub
Private Sub CommandButton2_Click()
Tag = 0
Hide
End Sub
https://www.gmayor.com/Userform.htm