I am using sendkeys in a rather complicated macro to autofill 4 PDF documents based on excel source data. Because I am only able to fill, reset or print and not able to save the filled in documents, I would like to use the "Microsoft Print to PDF" printer to save the filled in PDF. I have searched the web ad nauseum and ripped off many snippets of code including activeprinter and the like... Nothing is working... I am still kicking off an actual print job to my default printer. Since I do not want actual printed output but rather the PDF, this won't work... So I need to change the default printer so that when I send a print command via sendkeys to the document, the Save As window opens and saves to the filename. Does anyone have any thoughts or code that could help me with this?
'Beginning of Print code and get current default printer
Call GetProfileStringA("Windows", "Device", "", strLPT, 254)
Result = Application.Trim(strLPT)
ResultLength = Len(Result)
Comma1 = Application.Find(",", Result, 1)
Comma2 = Application.Find(",", Result, Comma1 + 1)
' Gets printer's name
startactiveprinter = Left(Result, Comma1 - 1)
' Gets driver
Driver = Mid(Result, Comma1 + 1, Comma2 - Comma1 - 1)
' Gets last part of device line
Port = Right(Result, ResultLength - Comma2)
startactiveprinter = startactiveprinter & " on " & Port
Printers = GetPrinterFullNames()
For N = LBound(Printers) To UBound(Printers)
testprint = Printers(N)
testprint = Left(testprint, 22)
If testprint = "Microsoft Print to PDF" Then
Application.ActivePrinter = Printers(N)
'SetDefaultPrinter (Printers(N))
Exit For
End If
Next N
'reset to original default printer
Application.ActivePrinter = startactiveprinter
'SetDefaultPrinter (startactiveprinter)
'Beginning of Print code and get current default printer
Call GetProfileStringA("Windows", "Device", "", strLPT, 254)
Result = Application.Trim(strLPT)
ResultLength = Len(Result)
Comma1 = Application.Find(",", Result, 1)
Comma2 = Application.Find(",", Result, Comma1 + 1)
' Gets printer's name
startactiveprinter = Left(Result, Comma1 - 1)
' Gets driver
Driver = Mid(Result, Comma1 + 1, Comma2 - Comma1 - 1)
' Gets last part of device line
Port = Right(Result, ResultLength - Comma2)
startactiveprinter = startactiveprinter & " on " & Port
Printers = GetPrinterFullNames()
For N = LBound(Printers) To UBound(Printers)
testprint = Printers(N)
testprint = Left(testprint, 22)
If testprint = "Microsoft Print to PDF" Then
Application.ActivePrinter = Printers(N)
'SetDefaultPrinter (Printers(N))
Exit For
End If
Next N
'reset to original default printer
Application.ActivePrinter = startactiveprinter
'SetDefaultPrinter (startactiveprinter)