View Single Post
 
Old 08-16-2020, 11:40 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

While would have used the code below to create the message, which will retain the user's signature, are you saying that you want the attachment that you have already attached to the message to include the date and time from the subject of the message? If so, that's not going to happen.


If you want the date and time in your pdf name then you should get the user to enter the time and date in your userform and apply them to the pdf before you create the message (and don't try and use the '/' character in that filename).


As you are using a userform to create the message, there is no point in getting the user to mess around with the created message. That message should be complete.



Code:
Private Sub sendreport_Click()
Dim OL As Object
Dim EmailItem As Object
Dim olInsp As Object
Dim wdDoc As Object
Dim oRng As Range
Dim Doc As Document
Dim strFileName As String
    Application.ScreenUpdating = False
    Set Doc = ActiveDocument
    Doc.Save
    strFileName = Replace(Doc.FullName, ".docx", ".pdf")
    Doc.ExportAsFixedFormat OutputFileName:=strFileName, _
                            ExportFormat:=wdExportFormatPDF

    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(0)    ' 0 = olMailItem

    With EmailItem
        .To = "tyrone@email.com.au; main@emails.com.au "
        .Importance = 1    ' olImportanceHigh
        .Subject = "Security handover report, for duty completion: 00/00/00 - 0000-0000"
        .Attachments.Add strFileName
        Set olInsp = EmailItem.GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range
        oRng.Collapse 1
        oRng.Text = "* SECURITY INSTRUCTION = Change date/time above in end of subject line + Add designation/name to signature area below + DELETE THIS LINE OF TEXT" & vbCrLf & _
                    "Dear Team Member," & vbCrLf & _
                    " Please find attached the Security Handover Report' for the completed duty period. " & vbCrLf & _
                    " TYRONE= TEST: AUTO Stationary is applied Y= EDIT VBA Remove this text & UPDATE .-TO-= Email Recipients list, Master file be kept in OneDrive with a desktop shortcut link on PC desktop. Fix to save with automated in both local store file and one attached<<< REMOVE-AMMEND THIS TEXT Before going live"
        .Display
    End With
    Application.ScreenUpdating = True

    Set Doc = Nothing
    Set EmailItem = Nothing
    Set OL = Nothing
    Set wdDoc = Nothing
    Set olInsp = Nothing
    Set oRng = Nothing
    MsgBox "Please change the *DATE* & *SHIFT TIME* in the subject line of the email. Add your Designation/NAME to the signature in the email bottom and hit send... Word is going to save and close hit OK."
    ActiveDocument.Close SaveChanges:=wdSaveChanges
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote