简体   繁体   中英

Excel Print Area

I would like to be able to print everything I have from columns A:H in landscape mode, and I was wondering if anyone knows how to do this such that whenever you open this specific document and try to print it, it will automatically print under these specific settings. Additionally I would only like to print where there actually is text and avoid printing the white space (I have equations filled in all cells A1:H50, but I only actually have numbers filled in RIGHT NOW (but this will change over time) on cells A1:H30. ie A31:H50 are for now all filled with the empty space character "")

Additionally, the top row of my document has headers, which I would like to be displayed for every page that I print out. (ie headers of stock name, stock price, stock price 1 year ago, and then those columns are filled with 30 stocks). I would like it so that if I have 4 pages (variable) worth of information that end up being printed, that the top row of stock name and price always get printed at the top of each page.

Thanks a lot!

Okay you're asking a few different questions, and some are easier to answer than others.

Firstly, you want to set a specific area (A1:H50) to be printed every time someone prints the page, and you want it to print in landscape. This is simple - go to the Page Layout ribbon, select the area A1:H50, and click Print Area -> Set Print Area. Then right beside that, click Orientation -> Landscape.

Your third question, about setting a header, is also simple. Go to the Page Layout Ribbon again, and click on Print Tiles. You can either click on the Sheet tab and tell it to repeat some rows at the top, or you can click Header/Footer and manually type in the headers yourself.

Your second question does not have a simple, automated approach (that I know of. Either accept the fact that blank space will be included in the printout (which is fine anyway, as you likely want each page to be spaced the same anyway, regardless of how many rows are filled), or manually "Hide" blank rows.

VBA automated solutions would be possible here, but I don't recommend that you use an automated solution which you don't understand over something so trivial to do manually.

Note that this question is not really suited to this site. This is a question better suited to superuser.com, which is part of the same group of sites as stackoverflow.com, but is geared towards non-programming questions about software - especiallly Excel.

You could use a BeforePrint event to reset the print area to your specifications each time the user tries to print it. No matter what settings the user tries to choose, it would override with the ones you specify in the event code. Try putting the code below in the ThisWorkbook module:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Application.PrintCommunication = False
    With ThisWorkbook.Sheets("Sheet 1")
        .AutoFilterMode = False
        .Range("$A:$H").AutoFilter Field:=1, Criteria1:="<>", Operator:=xlFilterValues  'if column A (Field:=1) is blank then hide those rows before setting print range
        With .PageSetup
            .Orientation = xlLandscape
            .PrintArea = "$A:$H"
            .PrintTitleRows = "$1:$1" 'change to whichever row numbers you want to print on every page
        End With
    End With
    Application.PrintCommunication = True
End Sub

The potential upside/downside to doing it this way would be that it doesn't allow the user to print it in any format other than the one you specify. If you didn't want to limit the user's ability to print it in different formats, you could use the same code inside a non-event Sub and have the user run that macro whenever they need to print it out with these settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM