Run-time error using PdfSettings.OpenViewer setting

I'm writing some Excel code to generate a password protected PDF using VBA. It's working so far except I don't want the current PDF viewer opening after the file is saved. However, when I add the following line to my script, I get an run-time error:

PrintJob.SetProfileSetting "PdfSettings.OpenViewer", "false"
PrintJob.ConvertTo SavePath

image

At this point, Excel is broken and I have to exit Excel and re-load. Comment the line out and it works fine.

Ahh just realised by single stepping through that the error is on the setting of the profile string, not the convert. What’s wrong with the SetProfileSettings line?

Okay, got it sorted. One assumes that all settings were of the format “PdfSettings.something” but that’s not the case. The line should be:

PrintJob.SetProfileSetting "OpenViewer", "false"

The setting strings are a little inconsistent IMO.

Hi,

it actually makes sense, as the OpenViewer setting applies to all viewers/ file types, not only PDF files. Sorry for the late response, though.

Best regards,

Robin