+ Reply to Thread
Results 1 to 6 of 6

VBA code to have print button and print the required area in sheet.

  1. #1
    Registered User
    Join Date
    08-06-2014
    Location
    Pune, India
    MS-Off Ver
    2010
    Posts
    84

    VBA code to have print button and print the required area in sheet.

    Hi All,
    I have created a macro that formats the sheet as desired. I want the formatted sheet to show the Print button.
    This need to be part of macro that is formatting the sheet so that once sheet is formatted it should have the Print button on it.
    On click event of print button I need to print area A2:J33 in A4 page, landscape orientation.
    It should be a single page, comments are not needed to be printed.
    Print dialogue box should be available to user , either to select the active printer or to print as PDF.

    I tried inserting a button and assign the recorded print macro. It works, but than user has to every time manually assign a macro to a button, which I am trying to avoid.

    Thank you for the help in advance.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: VBA code to have print button and print the required area in sheet.

    Interesting. Can you post your workbook here so we can see what is happening ?

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code to have print button and print the required area in sheet.

    This example code will add a print button to cell B2 with the caption "Print" and assign Macro1 to it.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    08-06-2014
    Location
    Pune, India
    MS-Off Ver
    2010
    Posts
    84

    Re: VBA code to have print button and print the required area in sheet.

    Hi AlphaFrog,
    Thanks for answering the question.
    I have added the button as per above code and assigned the recorded Macro1 to it.
    But some how the Macro1 selects required range A2:J33 but it does not pop up the print view settings.
    This will help user either to select active printer or print as PDF. Attachment has the recorded Macro1.
    Please help.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-06-2014
    Location
    Pune, India
    MS-Off Ver
    2010
    Posts
    84

    Re: VBA code to have print button and print the required area in sheet.

    Hi AlphaFrog,
    I have edited the code. Please refer the Macro2 code in module 2.
    Print preview is now visible.
    Appreciate your time on this.
    Thank you.
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code to have print button and print the required area in sheet.

    You're welcome.

    This will display the Print dialog.

    Application.Dialogs(xlDialogPrint).Show

+ 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. how to create macro button to print a selected area of sheet2 from another sheet
    By EMAIL4DEEPAKRAJ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2015, 06:29 AM
  2. Correct VBA Code to Print Defined Print Area
    By newqueen in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-27-2014, 04:31 PM
  3. Code and Formula to print dynamic print area ranges
    By stpeter in forum Excel General
    Replies: 1
    Last Post: 10-15-2013, 03:33 PM
  4. [SOLVED] Need ‘Set Print Area’ Code for Dynamic Print Range based on Conditions
    By dosbirn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2013, 12:13 PM
  5. [SOLVED] Print array code for a series of pages that will also determine print area required?
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2012, 11:46 PM
  6. [SOLVED] VBA code to print out certain area in a sheet
    By imran91 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2012, 05:16 PM
  7. Replies: 1
    Last Post: 11-24-2005, 07:29 AM

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