# VBA set custom Printer and Papersize



## willow1985 (Dec 29, 2022)

I have been searching online but cannot seem to find a VBA code that works to set the printer to Foxit PDF and select a custom paper size. I can manually do it but would like a code to set this so the users do not have to.
If anyone can help me with this it would be greatly appreciated!


----------



## rlv01 (Dec 31, 2022)

Have you tried using the Excel Macro Recorder to record your actions as you perform the actions manually? That should help to sort out the needed VBA syntax.


----------



## willow1985 (Tuesday at 11:55 AM)

rlv01 said:


> Have you tried using the Excel Macro Recorder to record your actions as you perform the actions manually? That should help to sort out the needed VBA syntax.


Unfortunately I have tried this but running it back it still does not change to the settings shown above unfortunately.


----------



## rlv01 (Tuesday at 12:49 PM)

Maybe something like this,

```
If InStr(UCase(Application.ActivePrinter), "PDF") = 0 Then
      MsgBox "Please select the Foxit PDF printer", vbOKOnly Or vbInformation, Application.Name
      With Application.Dialogs(xlDialogPrinterSetup)
          If .Show = -1 Then    'User picked a printer
          Else                  'The user pressed Cancel
              MsgBox "User Cancel"
              Exit Sub
          End If
      End With
    End If
       
    If InStr(UCase(Application.ActivePrinter), "PDF") = 0 Then
        MsgBox "Invalid printer selected", vbOKOnly Or vbExclamation, Application.Name
        Exit Sub
    End If
```


----------

