Share via

Simulate Ctrl+P in VBA

Anonymous
2016-01-06T08:07:24+00:00

Hi all,

I'm looking for a code that can simulate Ctrl+P. I have tried Dialogs(wdDialogFilePrint).Show but it doesn't have (or I couldn't find after 20mins) the option to include all column in one page.

Therefore I need a code that basically simulates Ctrl+P to the excel.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Vijay A. Verma 104.9K Reputation points Volunteer Moderator
2016-01-06T10:50:34+00:00

Use following statement in your VBA code -

Application.CommandBars.ExecuteMso ("PrintPreviewAndPrint")

Was this answer helpful?

40+ people found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-01-07T06:34:41+00:00

    Hey, any idea what is the command to send the user under "Save As"?

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2016-01-07T05:59:26+00:00

    Hi Vijay, that was exactly what I needed, thanks!

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2016-01-06T09:28:41+00:00

    Hi Benedict,

    I'm looking for a code that can simulate Ctrl+P. I have tried Dialogs(wdDialogFilePrint).Show but it doesn't have (or I couldn't find after 20mins) the option to include all column in one page.

    Therefore I need a code that basically simulates Ctrl+P to the excel.

    Try something like:

    '==========>>

    Option Explicit

    '--------->>

    Public Sub Tester()

        With ActiveSheet

            With .PageSetup

                .Zoom = False

                .FitToPagesWide = 1

                .FitToPagesTall = 10  

            End With

            '\ to preview:

            .PrintPreview

            '\ or, to print, remove initial apostrophe on next line

            '.printout

        End With

    End Sub

    '<<=========

    ===

    Regards,

    Norman

    Was this answer helpful?

    0 comments No comments