I need to generate a pdf in word and automatically attach it to an email with outlook 2011, what is the best way to do this?
thank you
I need to generate a pdf in word and automatically attach it to an email with outlook 2011, what is the best way to do this?
thank you
Hi @Enrico_Angelini,
It would be good to see what you tried so far.
I have neither of these applications and my suggestion would always be to build this up through a little sequence of āingredientsā which you can then pull together.
So first you want to create a macro which generates your PDF file. Nothing else - just that.
Then create something which creates a new draft in Outlook.
Then another which enables an attachment in Outlook
Once these are working, you can string them together by having a macro which contains the three other macros. So the macro
"Generate PDF in Word an attach to draft"
is simply made up of these three macros:
Execute macro "Generate PDF from Word"
Execute macro "Create draft in Outlook"
Execute macro "Attach file in Outlook"
The luxury here is that you can then use these ingredients elsewhere!
Then, as you use it, you may say: I hate navigating to find my PDF file.
OK, then an create another macro which you can add in and which does this:
"Copy PDF to MyTempFolder"
Then you can adjust the āAttach file in Outlookā macro to always look in MyTempFolder - and even delete the files afterwards.
In summary: Create your ingredients, then string them together, then improve.
Hi,
i attach two screenshots that better explain what i need.
the first shows the word's print window and i would like to click in lower
left corner on the pdf button, the second shows the menu that i get when i
click on the pdf button and i want to choose the outlook option that
automatically attach the pdf in a new outlook email.
I don't understand how to use the action "move or click mouse" to do what i
want, also because i think i will need this feature in many other cases
Enrico Angelini
Da: Rather kmforum@forum.keyboardmaestro.com
Risposta: Keyboard Maestro Discourse
replies+9ddfcea871147c2d01a0a186699d729c@forum.keyboardmaestro.com
Data: venerdƬ 8 agosto 2014 18:44
A: Enrico Angelini angelini.enrici@gmail.com
Oggetto: Re: [Keyboard Maestro] Attach a pdf to an email
Donāt select by āmove or click mouseā ā select by using action
"Insert text (by typing) "outlā "
this is the second step, but how can i click on the pdf button?
thank you for your patienceĀ
Enrico Angelini
Da: rolian kmforum@forum.keyboardmaestro.com
Risposta: Keyboard Maestro Discourse
replies+293efe2ad7666cb775358e2a967f7e88@forum.keyboardmaestro.com
Data: venerdƬ 8 agosto 2014 20:24
A: Enrico Angelini angelini.enrici@gmail.com
Oggetto: Re: [Keyboard Maestro] Attach a pdf to an email
I wonāt be at my Mac until tomorrow morning, but it was either
a button press or menu item action - Iāll check when I can and
let you know. I print to evernote from that same menu, so I can
just show that and you can adjust to type āOutlā instead of the
"Send to Ev" that i use
Hey Enrico,
This is a job for AppleScript.
While you can drive the UI to get the job done, you have far more control with a scripted solution.
It will run a bit faster if you save it from the Applescript Editor to a script (.scpt) file, and run a script file in your Execute AppleScript action. (But it won't hurt anything to run it as a text script.)
-Chris
----------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014-08-08 : 16:50
# dMod: 2014-08-08 : 17:07
# Appl: Microsoft Outlook, Microsoft Word
# Task: Create PDF from Active-Document in Word and attach to new
#Ā Ā Ā Ā Ā : Outlook message.
# Tags: @Applescript, @Script, @Microsoft_Outlook, @Microsoft_Word
# Note: Tested on OSX 10.9.4 - Word & Outlook from Office 2011
----------------------------------------------------------------------
try
----------------------------------------------------------------------
set emlName to "Your Recipient's Name"
set emlAdrs to "emailRecipient@null.com"
set emlSubject to "Your Email Subject"
----------------------------------------------------------------------
set desktopPath to path to desktop as text
----------------------------------------------------------------------
tell application "Microsoft Word"
tell active document
set AppleScript's text item delimiters to ".docx"
set docName to (text item 1 of (get its name)) & ".pdf"
set newFilePath to desktopPath & docName
save as file name newFilePath file format format PDF
end tell
end tell
----------------------------------------------------------------------
tell application "Microsoft Outlook"
activate
set newMsg to make new outgoing message with properties {subject:emlSubject}
tell newMsg
make new recipient with properties {email address:{name:emlName, address:emlAdrs}}
make new attachment with properties {file:alias newFilePath}
end tell
open newMsg
end tell
----------------------------------------------------------------------
on error e number n
set e to e & return & return & "Num: " & n
if n ā -128 then
try
tell current application to button returned of (display dialog e with title Ā¬
"ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} Ā¬
default button "OK" giving up after 30)
if ddButton = "Copy" then set the clipboard to e
end try
end if
end try
----------------------------------------------------------------------
I meant to mention:
I save my AppleScripts in the same structure used by Appleās own AppleScript Menu, which is also used by FastScripts. You can of course put them anywhere you wish, but Iāve gotten used to this modality over a couple of decades.
~/Library/Scripts/Applications/Microsoft Word/<your script name>
Paste the following line into the Terminal to create this folder and automatically go there in the Finder. (Do NOT copy the return on the end of the line, or it will automatically execute when you paste in into the Terminal.)
DIR=~/'Library/Scripts/Applications/Microsoft Word/'; mkdir -p "$DIR"; sleep 0.25; open "$DIR";
-Chris
Hi Chris
This has worked a treat for ages but in the recent iteration of Catalina, I get an error.
The error is: "Microsoft Outlook got an error: Canāt get alias "Macintosh HD:Users:andrewkornberg:Desktop:File Name.pdf" of outgoing message id 824487.
Not sure what has changed.
Thanks
Andrew
The code is:
try
----------------------------------------------------------------------
set emlName to "XXXX"
set emlAdrs to "XXXX"
set emlSubject to "For upload and sending out please. Thanks +++"
----------------------------------------------------------------------
set desktopPath to path to desktop as text
----------------------------------------------------------------------
tell application "Microsoft Word"
tell active document
set AppleScript's text item delimiters to ".docx"
set docName to (text item 1 of (get its name)) & ".pdf"
set newFilePath to desktopPath & docName
save as file name newFilePath file format format PDF
end tell
end tell
----------------------------------------------------------------------
tell application "Microsoft Outlook"
activate
set newMsg to make new outgoing message with properties {subject:emlSubject}
tell newMsg
make new recipient with properties {email address:{name:emlName, address:emlAdrs}}
make new attachment with properties {file:alias newFilePath}
end tell
open newMsg
end tell
----------------------------------------------------------------------
on error e number n
set e to e & return & return & "Num: " & n
if n ā -128 then
try
tell current application to button returned of (display dialog e with title Ā¬
"ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} Ā¬
default button "OK" giving up after 30)
if ddButton = "Copy" then set the clipboard to e
end try
end if
end try
----------------------------------------------------------------------