You can't, unfortunately.
In a now-removed Microsoft KB article Q166818, originally dating back to 1997 and last updated in 2006, Microsoft documents that PowerPoint's active printer device cannot be changed via COM Automation nor by VBA:
The ActivePrinter
property is read-only in the PowerPoint object library and cannot be changed programmatically.
Unfortunately I don't know why this is the case, and it seems such an obvious thing to include. I did try to speculate some reasons, but I can't think of a reasonable excuse for why Word, Excel, and even Access let VBA/COM change the current Application.Printer
but PowerPoint doesn't, especially not after over 20 years of continuous development. But I do note that PowerPoint's support for VBA and COM automation is lacking overall compared to other Office programs, for example there's no Macro Recorder feature - so maybe it just wasn't a development priority and not enough people threatened to not buy the next version of PowerPoint until this specific feature was added - such is how software development works.
BTW, the Presentation.PrintOptions
property exposes the print-options saved into the .ppt
/.pptx
file, which presumably will be those of the computer that the presentation was authored and last-saved on, rather than print settings appropriate for the current computer's printer.
A possible workaround might exist if you first set the Windows's default printer (or in VBA), and then just call the PrintOut()
method and hope that the correct printer is used.
Something like this (I have not tested this code, I don't know if it works or not):
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.PowerPoint;
internal static class NativeMethods
{
// https://learn.microsoft.com/en-us/windows/win32/printdocs/setdefaultprinter
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetDefaultPrinter(string name);
}
public static class MyProgram
{
public void DoStuff()
{
Application ppt = new Application();
Presentation doc = ppt.Presentations.Open(file);
ppt.Activate();
if( !NativeMethods.SetDefaultPrinter("Adobe PDF") )
{
throw new InvalidOperationException( "Couldn't set default printer." );
}
doc.PrintOut();
ppt.Quit();
}
}