Man is a slow, sloppy, and brilliant thinker; computers are fast, accurate, and stupid.
- John Pfeiffer

Top Ten Tags

Who's Online

If sheets in a workbook have different DPI values (dot per inch, i.e. affects print resolution / quality) and you try to print them all at once to a PDF printer, Excel will print them as separate files. This code will set the DPI for ALL sheets to a single DPI value, i.e. 1200 dpi.

VBA Code

Sub SetDPI()
    Dim wb As Workbook, ws As Worksheet

1   On Error GoTo ErrMsg

2   Application.ScreenUpdating = False
3   Application.Cursor = xlWait

4   Set wb = ActiveWorkbook

5   For Each ws In wb.Sheets

        'Debug.Print ws.Name
6       Application.StatusBar = "Setting DPI for worksheet = " & ws.Name
7       ws.PageSetup.PrintQuality = 1200

8   Next ws

ExitHere:
9   Set wb = Nothing
10  Application.ScreenUpdating = True
11  Application.StatusBar = ""
12  Application.Cursor = xlDefault
13  Exit Sub

ErrMsg:
14  MsgBox "An error has occurred @ line # " & Erl & " in SetDPI()." & vbNewLine & vbNewLine & _
           "Error Number:" & Err.Number & " (" & Err.Description & ").", vbCritical, "Error!"
15  Debug.Print "SetDPI()"
16  Debug.Print "Err.Number = " & Err.Number
17  Debug.Print "Err.Description = " & Err.Description
18  Debug.Print "Erl = " & Erl
19  Resume ExitHere

End Sub