I have a button on a workbook template that will save the work book and attach it to an email. I want to incorporate the ID number into the subject of the email. This number is changed each time the template is used.
For example: If the ID number is 000001, I want the email subject to read "Workbook #000001: Approval Required"
My Code:
Private Sub CommandButton1_Click()
ActiveWorkbook.Save
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim PAAID As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hello," & vbNewLine & vbNewLine & _
"The attached PAA Form is complete and needs approval. Please review and return with approval or revision comments." _
& vbNewLine & vbNewLine & _
"Best regards," _
& vbNewLine & vbNewLine & _
"Strategic Procurement"
On Error Resume Next
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "PAA: PAAID = Range("Price Adjustment Approval!T2").Value Approval Required"
.Body = xMailBody
.Attachments.Add (ActiveWorkbook.FullName)
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Other than getting the cell value in the subject line, the code works just fine.
For example: If the ID number is 000001, I want the email subject to read "Workbook #000001: Approval Required"
My Code:
Private Sub CommandButton1_Click()
ActiveWorkbook.Save
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim PAAID As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hello," & vbNewLine & vbNewLine & _
"The attached PAA Form is complete and needs approval. Please review and return with approval or revision comments." _
& vbNewLine & vbNewLine & _
"Best regards," _
& vbNewLine & vbNewLine & _
"Strategic Procurement"
On Error Resume Next
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "PAA: PAAID = Range("Price Adjustment Approval!T2").Value Approval Required"
.Body = xMailBody
.Attachments.Add (ActiveWorkbook.FullName)
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Other than getting the cell value in the subject line, the code works just fine.