• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Automatically set print AREA.

sajjjid

Member
How can i Automatically set print area from H1 to K10.
And use a button as PrintArea1 and PrintArea2.
Thanks.
 
Hi,

This should probably be in the VBA section...
In any case, you may want to try the following:
Code:
Sub print_area1()

    Range("H1:K10").PrintPreview 'use this one to show preview before printing
'    Range("H1:K10").PrintOut 'use this one to print without showing preview

End Sub

Sub print_area2()

    Range("A1:C10").PrintPreview 'use this one to show preview before printing
'    Range("A1:C10").PrintOut 'use this one to print without showing preview

End Sub

Hope this helps
 
Hi,

This should probably be in the VBA section...
In any case, you may want to try the following:
Code:
Sub print_area1()

    Range("H1:K10").PrintPreview 'use this one to show preview before printing
'    Range("H1:K10").PrintOut 'use this one to print without showing preview

End Sub

Sub print_area2()

    Range("A1:C10").PrintPreview 'use this one to show preview before printing
'    Range("A1:C10").PrintOut 'use this one to print without showing preview

End Sub

Hope this helps
Thanks.
One more thing usually i print only two setup.
So, I need if suppose A1=1 then print area is H1:K10 if A1=2 then Print area is L1:M10.
One more thing i want to add. Paper Orientation should be landscape. Thanks.
 
Thanks.
One more thing usually i print only two setup.
So, I need if suppose A1=1 then print area is H1:K10 if A1=2 then Print area is L1:M10.
One more thing i want to add. Paper Orientation should be landscape. Thanks.
This should do it:
Code:
Sub print_area()

    ActiveSheet.PageSetup.Orientation = xlLandscape
   
    Select Case Range("A1")
        Case Is = 1
            Range("H1:K10").PrintPreview
        Case Is = 2
            Range("L1:M10").PrintPreview
    End Select

End Sub
 
This should do it:
Code:
Sub print_area()

    ActiveSheet.PageSetup.Orientation = xlLandscape
  
    Select Case Range("A1")
        Case Is = 1
            Range("H1:K10").PrintPreview
        Case Is = 2
            Range("L1:M10").PrintPreview
    End Select

End Sub

Thanks. It works very nicely.
Instead of Landscape if vertical then i have to edit as "xlVertical"?

Custom Scaling i am using 150. How i will add this.
Thanks. Again.
 
Hi,

Vertical should be ".Orientation = xlPortrait";
Custom scaling should be ".Zoom = 150":

Code:
Sub print_area()

    With ActiveSheet.PageSetup
        .Orientation = xlLandscape
        .Zoom = 150
    End With
 
    Select Case Range("A1")
        Case Is = 1
            Range("H1:K10").PrintPreview
        Case Is = 2
            Range("L1:M10").PrintPreview
    End Select

End Sub
 
Hi,

Vertical should be ".Orientation = xlPortrait";
Custom scaling should be ".Zoom = 150":

Code:
Sub print_area()

    With ActiveSheet.PageSetup
        .Orientation = xlLandscape
        .Zoom = 150
    End With

    Select Case Range("A1")
        Case Is = 1
            Range("H1:K10").PrintPreview
        Case Is = 2
            Range("L1:M10").PrintPreview
    End Select

End Sub

Thanks. Its getting better now.
1>pages to print = 1, how i will add?
2>I always print from sheet1, how can i add this?
3>Another code if i want to print both pages in one go.
from "B1:F29" and from "H1:L29"
4>Another code if i want to print from "B1:L29 as pdf.
Folder = e:\Shops and file name as Previous month or value "A2"
Thanks Again.
 
Hi,

In the future post the full problem/request right form the start!

To specify the sheet from where to print use "Sheets("Your sheet name here")." before Range... (see below)
In order to specify the number of copies, you will need to use Printout instead (which does not show a preview) (also below)
To print 2 sheets in one go simple add both instructions one after the other (refer to the "print_2sheets()" subroutine)
Export to PDF also below:

Code:
Sub print_area()

    With Sheets("Sheet1").PageSetup
        .Orientation = xlLandscape
        .Zoom = 150
    End With

    Select Case Sheets("Sheet1").Range("A1")
        Case Is = 1
            Sheets("Sheet1").Range("H1:K10").PrintOut copies:=1
        Case Is = 2
            Sheets("Sheet1").Range("L1:M10").PrintOut copies:=1
    End Select

End Sub

Sub print_2sheets()

    Sheets("Sheet1").Range("B1:F29").PrintOut
    Sheets("Sheet2").Range("H1:L29").PrintOut

End Sub

Sub ExportToPDF()

    Range("B1:L29").ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:="E:\Shops\" & Range("A2") & ".pdf"

End Sub
 
Hi,

In the future post the full problem/request right form the start!

To specify the sheet from where to print use "Sheets("Your sheet name here")." before Range... (see below)
In order to specify the number of copies, you will need to use Printout instead (which does not show a preview) (also below)
To print 2 sheets in one go simple add both instructions one after the other (refer to the "print_2sheets()" subroutine)
Export to PDF also below:

Code:
Sub print_area()

    With Sheets("Sheet1").PageSetup
        .Orientation = xlLandscape
        .Zoom = 150
    End With

    Select Case Sheets("Sheet1").Range("A1")
        Case Is = 1
            Sheets("Sheet1").Range("H1:K10").PrintOut copies:=1
        Case Is = 2
            Sheets("Sheet1").Range("L1:M10").PrintOut copies:=1
    End Select

End Sub

Sub print_2sheets()

    Sheets("Sheet1").Range("B1:F29").PrintOut
    Sheets("Sheet2").Range("H1:L29").PrintOut

End Sub

Sub ExportToPDF()

    Range("B1:L29").ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:="E:\Shops\" & Range("A2") & ".pdf"

End Sub

Thanks. Again.
Sorry for questioning again and again.
I was just curious to learn more from you.
Did not do intentionaly.
Thanks. Bye.
 
Back
Top