View Single Post
 
Old 08-16-2020, 10:32 PM
Taylormations Taylormations is offline Windows 10 Office 2016
Novice
 
Join Date: Aug 2020
Posts: 7
Taylormations is on a distinguished road
Default Command button. To multi command

Hi Guys I'm a return visitor from years back.

So consider me a noob. Especially in macro/vba world.


I'm struggling with my form
It's a command button that launches to save template file with original title and adds date and time in plain text format 000000_0000.

Then to save a pdf file locally in the 1 folder and attach it to a email with predefined recipients and body text.

Currently it's doing everything accept adding date and time it appears to be replacing itself and converting the file as it.

I have tried countless times and had to resort to a foundation script many times due to messing it up royally.

Code below

Private Sub sendreport_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim strFileName As String
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0) ' 0 = olMailItem
Set Doc = ActiveDocument
strFileName = Replace(Doc.FullName, ".docm", ".pdf")
Doc.ExportAsFixedFormat OutputFileName:=strFileName, _
ExportFormat:=wdExportFormatPDF
With EmailItem
.Subject = "Security handover report, for duty completion: 00/00/00 - 0000-0000"
.Body = "* 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"
.To = "tyrone@email.com.au; main@emails.com.au "
.Importance = 1 ' olImportanceHigh
.Attachments.Add strFileName
.Display
End With
Application.ScreenUpdating = True

Set Doc = Nothing
Set EmailItem = Nothing
Set OL = 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


I appreciate any help regards.
Reply With Quote