Consulting

Results 1 to 9 of 9

Thread: Solved: Print Selective Area

  1. #1
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location

    Lightbulb Solved: Print Selective Area

    Dear All,

    I am looking forwards to make a print by using VBA Code for selective area.

    I have Sheet2.Range(AL2:AV34) to be selected and Print.

    Print Properties,
    A. Selection Print for given area.
    B. Selection Area Fits in to the A4 paper as maximum as. (As Tall and Wide)
    C. Print Orientation, Landscape

    Regards,

    Rahul

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Rahul,

    Try recording a macro, selecting the options you want for printing. I believe it would be fairly easy to modify from the resultant macro.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    You could start with the following as an initial point of entry to the macro
    [VBA]
    Sub Print_Area()

    Range("AL2:AV34").Select
    With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.708661417322835)
    .RightMargin = Application.InchesToPoints(0.708661417322835)
    .TopMargin = Application.InchesToPoints(0.748031496062992)
    .BottomMargin = Application.InchesToPoints(0.748031496062992)
    .HeaderMargin = Application.InchesToPoints(0.31496062992126)
    .FooterMargin = Application.InchesToPoints(0.31496062992126)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 200
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlLandscape
    .Draft = False
    .PaperSize = xlPaperA4
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .PrintErrors = xlPrintErrorsDisplayed
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .ScaleWithDocHeaderFooter = True
    .AlignMarginsHeaderFooter = True
    .EvenPage.LeftHeader.Text = ""
    .EvenPage.CenterHeader.Text = ""
    .EvenPage.RightHeader.Text = ""
    .EvenPage.LeftFooter.Text = ""
    .EvenPage.CenterFooter.Text = ""
    .EvenPage.RightFooter.Text = ""
    .FirstPage.LeftHeader.Text = ""
    .FirstPage.CenterHeader.Text = ""
    .FirstPage.RightHeader.Text = ""
    .FirstPage.LeftFooter.Text = ""
    .FirstPage.CenterFooter.Text = ""
    .FirstPage.RightFooter.Text = ""
    End With
    ActiveWindow.SelectedSheets.PrintPreview
    End Sub[/VBA]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Hi GTO,

    I did the same in Initial Step where I received the error in Fittopagewide must be between 10 to 400. Therefore, I posted the thread.

    Dear Aussiebear,
    I am getting debug, .PrintQuality = 200 and if I choose RUN to cursor. Then at end shows, PrintPreview.
    I need Print, in One Page.

    Thanks

    Rahul

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Clear the print area, then carefully step through the options you wwant while recording. Show us the result. BTW, PrintQuality only works on certain printers I believe.

  6. #6
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Not getting result in Solving Thread, pls advise anyone.

  7. #7
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    ------------------------------------------------
    Happy Coding my friends

  8. #8
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    Quote Originally Posted by r_know
    I am getting debug, .PrintQuality = 200 and if I choose RUN to cursor. Then at end shows, PrintPreview.
    I need Print, in One Page.
    What steps have you taken?

    I recorded that section of code and followed the requests that you asked for, other than the actual print. GTO & I have given you a very good start to the macro. Have you tried recording a macro yourself?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  9. #9
    VBAX Contributor
    Joined
    May 2010
    Posts
    106
    Location
    Finally Work....

    Thanks for all your suggestions........

    [vba]Sub PrintTS()
    ActiveSheet.Range("AL2:AV34").Select
    With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.5)
    .RightMargin = Application.InchesToPoints(0.5)
    .TopMargin = Application.InchesToPoints(0.5)
    .BottomMargin = Application.InchesToPoints(0.5)
    .HeaderMargin = Application.InchesToPoints(0.5)
    .FooterMargin = Application.InchesToPoints(0.5)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 600
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlLandscape
    .Draft = False
    .PaperSize = xlPaperLetter
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .PrintErrors = xlPrintErrorsDisplayed
    End With
    Selection.PrintOut Copies:=1, Collate:=True
    ActiveSheet.Range("AL2").Select
    End Sub
    [/vba]

Posting Permissions

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