Results 1 to 7 of 7

Correct VBA Code to Print Defined Print Area

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007
    Posts
    144

    Correct VBA Code to Print Defined Print Area

    Hi All,

    I need help to tweak a VBA code that I have to enable me to print a defined Print Area of a Sheet.

    Here is the Print Code that I already have:

    Sub RoundedRectangle21_Click()
     
     '================== 
     ' PRINT Document
     '================== 
     
     Dim ans As Variant
        ans = MsgBox("Do You Wish To Print This Document?", vbYesNoCancel, "Print and Save Document")
        If ans = vbNo Then
            Exit Sub
        ElseIf ans = vbCancel Then  ' Don't Print & Save. Revert back to Document
            Exit Sub
        ElseIf ans = vbYes Then         ' Print and Save file
    
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
    End If
    However, it does not print my defined Print Area which is "F13:M40". I need help to incorpirate this Print Area into the code, please.

    I found a little print code which I incorporated into it - by removing the last two lines above, and adding the bolded lines, as shown follows:

    Sub RoundedRectangle21_Click()
     
     '================== 
     ' PRINT Document
     '================== 
     
     Dim ans As Variant
        ans = MsgBox("Do You Wish To Print This Document?", vbYesNoCancel, "Print and Save Document")
        If ans = vbNo Then
            Exit Sub
        ElseIf ans = vbCancel Then  ' Don't Print & Save. Revert back to Document
            Exit Sub
        ElseIf ans = vbYes Then         ' Print and Save file
    
     
             With Worksheets("Data")
            .PageSetup.PrintArea = "F13:M40"
            .PrintOut
        End With
    End If
    With my limited VBA knowledge, I believe that I did something very incorrect there. Hence, when I run it, I get a Runtime Error 9. Please, kindly help.

    I also wish to use the PRINT command button specifically for the work book. I do not wish a user to print any other sheet within the workbook. Please, I also need help to disable the Excel 'Print' feature for the workbook (if it is possible), so that only the above Print Command would be active.

    Thank you for your anticipated help.

    Newqueen
    Last edited by newqueen; 01-23-2014 at 01:54 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. 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
  2. [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
  3. [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
  4. Replies: 8
    Last Post: 05-23-2007, 06:39 AM
  5. Print Area:What would be the code for setting the print area
    By wammer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2005, 02:05 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