How to show print dialog box and have preview display on same screen

Andrew picture Andrew · Mar 7, 2016 · Viewed 15.3k times · Source

I am trying to emulate Ctrl-P in Excel 2013 where the print dialog box is shown on the left with the print preview on the right.

(Although where the preview displays, I always have to click "Show Print Preview" first - I can't seem to find a way to force the preview to show every time).

I have tried the following:

Application.Dialogs(xlDialogPrint).Show

This shows the old style dialog box where you need to click the "Preview" button

ActiveSheet.PrintPreview

This shows the preview but doesn't allow the printer to be changed from the same screen

Answer

0m3r picture 0m3r · Mar 7, 2016

Something like this?

Excel

Option Explicit
Public Sub Example()
    Application.CommandBars.ExecuteMso ("PrintPreviewAndPrint")
End Sub

CommandBars.ExecuteMso Method (MSDN) is useful method in cases where there is no object model for a particular command.

For Outlook

Option Explicit
Public Sub Example()
    Dim Inspector As Outlook.Inspector
    Set Inspector = Application.ActiveInspector

    If Not Inspector Is Nothing Then
        Dim cmd As Office.CommandBars
        Set cmd = Inspector.CommandBars

        cmd.ExecuteMso ("FilePrintPreview")
    Else
        ActiveExplorer.selection(1).Display
        Set cmd = ActiveInspector.CommandBars
        cmd.ExecuteMso ("FilePrintPreview")
    End If
End Sub