I'm writing a script to automate some repetitive admin stuff at work. The first step is printing an email from Outlook to a PDF (I'm using Word instead of Outlook here, because I don't use Outlook at home, but its exactly the same). I've done some digging and figured out how to change the default printer, and then use COM to print. So far so good.
The problem is that Print to PDF brings up a window to select where you want to save the PDF, but it doesn't end the Printout method until you get rid of that window. I want to have my script interact with that window, and select the destination for me. How do I get it to ignore the fact that the method isn't completed, and proceed to the Click regardless?
Code: Select all
Lwin & p::
SetDefaultPrinter(Microsoft Print to PDF)
ItemToPrint := ComObjActive("Word.Application").ActiveDocument
ItemToPrint.Printout
Click, Edit2, Save Print Output As ahk_exe WINWORD.EXE
SetDefaultPrinter(sPrinter)
{
DllCall(A_WinDir . "\system32\winspool.drv\SetDefaultPrinter", "str", sPrinter)
}