replace subject line generated by converting a word document to PDF and sending it to an email

Status
Not open for further replies.

Carla100

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I hoping to find a solution to my issue. I will be in a word document and utilize the "Email as a PDF Attachment" button I've stuck up on my quick access tool bar. It nicely generates an email all ready to go with the PDF attachment. unfortunately, it sticks something in the subject line. I need to replace that with some standard information that I have to put in all those emails. Emails generated in this particular way don't want to let me run anything without having saved it and closed it. When I reopen it I can take some action. Has anyone a script that would save, close open and replace whatever the generated subject line is with some standard line I create? It is over my head and I'm not finding exactly what I need. I'm hoping it exists!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Will you always save the file to the same location? I have a macro - this saves the pdf in the same location as the docx file, but as long as we have a filename and a path, it can go anywhere.


Code:
Sub SaveAndSendPDF()
 Dim olApp 'As Outlook.Application
 Dim olItem 'As Outlook.MailItem
 
 Dim dlgSaveAs As FileDialog
  Dim strPath As String
  Dim PDFFilePath As String
  Dim PDFFileName As String

 Set dlgSaveAs = Application.FileDialog( _
 FileDialogType:=msoFileDialogSaveAs)
 dlgSaveAs.Show

strPath = _
        Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)

  strPath = Left$(strPath, InStrRev(strPath, ".") - 1)
 PDFFilePath = strPath & ".pdf"

ActiveDocument.ExportAsFixedFormat OutputFileName:=PDFFilePath_
        , ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=False, _
        CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=False, UseISO19005_1:=False

'strPath = ActiveDocument.FullName ', ActiveDocument.
     
'Start Outlook if it isn't running
 Set olApp = GetObject(, "Outlook.Application")
 If Err <> 0 Then
 Set olApp = CreateObject("Outlook.Application")
 End If

'Create a new message
 Set olItem = olApp.CreateItem(olMailItem)
 olItem.Display
 olItem.Attachments.Add PDFFilePath
 olItem.Subject = "my subject"
End Sub
 
Last edited:

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
BTW, can't you edit the subject of the open email without first saving and closing? (I can, but using outlook 2016.)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The macro i posted worked in 21016 but not 2010 - i fixed it so it works in 2010.
 
Last edited:

Carla100

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Well... Wow. Thank you Diane Poremsky! I actually don't need to save the PDF I'm sending these days, but I'm going to give that a whirl.

Yes something about Adobe PDF generated from word into an outlook email doesn't want to play nicely in 2010. outlook either wants you to send the email or save the email as a draft before it will let you take any other action in its email functions. It is a bit of a plague. It sounds like they have fixed that in later versions. Thank you, and I will give your script a go. That is really great. Thank you!
 

Carla100

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Hmmm. I gave it a shot Diane, In Word correct? I get an error message when I try and run it: Compile Error: Syntax error.
This part shows up in Red:
ActiveDocument.ExportAsFixedFormat OutputFileName:=PDFFilePath_
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=False, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=False, UseISO19005_1:=False

So I wonder if something has gone awry from copying it overh
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Yes, in word. i will test it again in 2010 and see if i can replicate it. one thing you can try is either add a space before the _ here: PDFFilePath_ or use backspace to move the comma so its PDFFilePath, exportformat....
 

Carla100

New Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Thank you so much Diane, I will try that.
 
Status
Not open for further replies.
Top