Define print settings when using Wscript.shell

cbrf23

Board Regular
Joined
Jun 20, 2011
Messages
241
Hi.
I have working code here that I can use to open or print a pdf.

When I run the testPrint subroutine, the document prints. Problem is it prints with the default print settings on size 8.5x11 paper. The document I'm printing does not fit correctly on this size paper.

I have saved a print settings file "BP_11x17.sav" which is currently in the same directory as the pdf file (my desktop).

I need to know how to tell Acrobat Reader to use this .sav file for the print settings.

Can anyone tell me how to do this?

Please consider:
*The excel file containing this code will be executed from multiple users at multiple workstations.
*All have acrobat reader, although some may have different versions then others.
*Location of the Acrobat Reader exe may not always be in same directory.
*Location of the print settings (BP_11x17.sav) will always be in the same directory, and will be accessible by everyone.
*I have no control over how each users VBA reference library is setup.

These concerns are why I am using the code below. I got this code off the web, so I dont understand all the parameters completely, but I do like the idea of just letting windows figure out the correct program association for whatever file I'm trying to manipulate.

I'm still pretty new when it comes to vba coding. I learn a lot with each new project, and I'm open to better ways of doing things.


Code:
Option Explicit
Public Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
 
Public Function PrintThisDoc(formname As Long, FileName As String)
'On Error Resume Next
Dim X As Long
X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function
 
Public Function OpenThisDoc(formname As Long, FileName As String)
'On Error Resume Next
Dim X As Long
X = ShellExecute(formname, "Open", FileName, 0&, 0&, 3)
End Function
 
Sub testOpen()
Dim openThis
Dim strDir              As String
Dim strFile             As String
Dim strloc              As String
strDir = "C:\Documents and Settings\MYNAME\Desktop"
strFile = "MYPRINT.pdf"
strloc = strDir & "\" & strFile
openThis = OpenThisDoc(0, strloc)
End Sub
 
Sub testPrint()
Dim printThis
Dim strDir              As String
Dim strFile             As String
Dim strloc              As String
strDir = "C:\Documents and Settings\MYNAME\Desktop"
strFile = "MYPRINT.pdf"
strloc = strDir & "\" & strFile
printThis = PrintThisDoc(0, strloc)
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top