Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-16-2020, 11:40 PM
gmayor's Avatar
gmayor gmayor is offline Command button. To multi command Windows 10 Command button. To multi command Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button herman777 Excel Programming 2 06-02-2019 06:45 AM
Show table list by using chek box command and save document on sharepoint by using command button Zhibek Word VBA 3 08-16-2018 06:19 PM
Help with a Command Button dkohnken Word VBA 5 03-18-2015 10:13 PM
Command Button knp11 PowerPoint 2 01-18-2015 01:41 PM
Command button. To multi command Command Button cksm4 Word VBA 7 02-27-2011 08:47 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft