+ Reply to Thread
Results 1 to 4 of 4

vba macro for print button that brings up print screen selection window

Hybrid View

  1. #1
    Registered User
    Join Date
    05-10-2016
    Location
    petrolia, pa
    MS-Off Ver
    10
    Posts
    11

    vba macro for print button that brings up print screen selection window

    I have a print button already created and the macro brings up the print screen selection window for the user but I need this window to already be populated with 'entire workbook' selection. The workbook is emailed to the user and they click the print button.
    Thank you

    'CREATE PRINT BUTTON
        ActiveSheet.Shapes.AddShape(msoShapeRectangle, 11.25, 76.5, 51, 17.25).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "PRINT"
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 5). _
            ParagraphFormat
            .FirstLineIndent = 0
            .Alignment = msoAlignLeft
        End With
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 5).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Fill.Visible = msoTrue
            .Fill.ForeColor.ObjectThemeColor = msoThemeColorLight1
            .Fill.ForeColor.TintAndShade = 0
            .Fill.ForeColor.Brightness = 0
            .Fill.Transparency = 0
            .Fill.Solid
            .Size = 11
            .Name = "+mn-lt"
        End With
        Selection.ShapeRange.ScaleWidth 0.8529411765, msoFalse, msoScaleFromTopLeft
        Selection.ShapeRange.ScaleHeight 1.1304347826, msoFalse, msoScaleFromTopLeft
        'Selection.OnAction = "PRINTWKBK"
        Range("A9").Select
        
    'add print macro to button
    ActiveSheet.Shapes.Range(Array("Rectangle 1")).Select
        Selection.OnAction = "PERSONAL.xlsb!ON_CLICK_PRINT"
        Range("A8").Select
    Last edited by 6StringJazzer; 02-24-2020 at 12:41 PM. Reason: Moderator fixed attempt at tagging code

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: vba macro for print button that brings up print screen selection window

    Hi there,

    I'm afraid the code you've posted (which seems to work correctly ) isn't much use to us - we need to see the code for the routine "ON_CLICK_PRINT" which is apparently in your "PERSONAL.xlsb" workbook.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    05-10-2016
    Location
    petrolia, pa
    MS-Off Ver
    10
    Posts
    11

    Re: vba macro for print button that brings up print screen selection window

    I believe that is where I am not understanding how to get the print button to work once the spreadsheet is emailed to the user. The on click is in my personal so how does one get it into the workbook that is being emailed?

    [Sub ON_CLICK_PRINT()
    Application.Dialogs(xlDialogPrint).Show
    End Sub]

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: vba macro for print button that brings up print screen selection window

    Hi again,

    Thanks for that information.

    See if the following code does what you need:

    
    
    
    Option Explicit
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    
    Sub PrintWorkbook()
    
        Const dHEIGHT   As Double = 1.2
        Const dWIDTH    As Double = 0.9
    
        Dim shp As Shape
    
        Set shp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 11.25, 76.5, 51, 17.25)
    
        With shp
    
            .Name = "btnPrint"
    
            .TextFrame2.TextRange.Characters.Text = "PRINT"
    
            With .TextFrame2.TextRange.Characters(1, 5)
    
                .ParagraphFormat.FirstLineIndent = 0
                .ParagraphFormat.Alignment = msoAlignLeft
    
                With .Font
    
                    .NameComplexScript = "+mn-cs"
                    .NameFarEast = "+mn-ea"
                    .Size = 11
                    .Name = "+mn-lt"
    
                    With .Fill
    
                        .ForeColor.ObjectThemeColor = msoThemeColorLight1
                        .ForeColor.TintAndShade = 0
                        .ForeColor.Brightness = 0
                        .Transparency = 0
                        .Visible = msoTrue
                        .Solid
    
                    End With
    
                End With
    
            End With
    
            .ScaleHeight 1.1304347826, msoFalse, msoScaleFromTopLeft
            .ScaleWidth 0.8529411765, msoFalse, msoScaleFromTopLeft
    
            .OnAction = "PRINTWKBK"         '     <<< Insert the appropriate routine name here
    
        End With
    
        ActiveSheet.Range("A9").Select
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Sub PRINTWKBK_Version_1()
    
    '   This routine prints the entire workbook without using the "Print" DialogBox
        ActiveWorkbook.PrintOut
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Sub PRINTWKBK_Version_2()
    
    '   This routine displays the "Print" DialogBox with the "EntireWorkbook" option selected
        Application.Dialogs(xlDialogPrint).Show , , , , , , , , , , , 3
    
    End Sub

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Print button that still prints when cancelled at the printer setup window
    By despdel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2020, 06:03 PM
  2. [SOLVED] Button To Print Specific cell Range On One Sheet In Print Selection
    By diddy47 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-03-2020, 06:23 AM
  3. [SOLVED] Print Button prints out a form different from the one showing on the screen
    By JET2011 in forum Access Tables & Databases
    Replies: 2
    Last Post: 01-31-2018, 03:39 PM
  4. Disabled print toolbar and menu but Print Macro button cannot print also...
    By zein97 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2014, 01:42 PM
  5. Overlay an option button form on a print preview screen
    By BuckP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2013, 04:29 PM
  6. How do you add a 'print screen' button to a form?
    By familylink in forum Excel General
    Replies: 4
    Last Post: 06-28-2010, 03:32 AM
  7. Replies: 1
    Last Post: 10-27-2005, 06:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1