Excel VBA print preview selected range

Michelle has a lengthy worksheet that she's working with. When she uses Print Preview for the worksheet, the page shown in the Print Preview dialog is always the first page. Michelle wonders if there is a way to make Print Preview automatically show the page of the worksheet on which she's working.

One way to approach this problem is to try working with print areas. If you select the area of the worksheet on which you are working and then set the print area equal to your selection, then when you display Print Preview, you should see only that print area.

If this does not accomplish your desire, then you might think you can resort to using a macro. Here's an example macro that may do the trick for you:

Sub PrintPreviewActivePage[] Dim lActiveRow As Long Dim iActiveCol As Integer Dim iHPBs As Integer Dim iVPBs As Integer Dim lRow As Integer Dim iCol As Integer Dim iPage As Integer lActiveRow = ActiveCell.Row iActiveCol = ActiveCell.Column ActiveSheet.UsedRange If IsEmpty[ActiveCell.SpecialCells[xlCellTypeLastCell]] Then _ ActiveCell.SpecialCells[xlCellTypeLastCell].FormulaR1C1 = " " If lActiveRow > ActiveCell.SpecialCells[xlCellTypeLastCell].Row Or _ iActiveCol > ActiveCell.SpecialCells[xlCellTypeLastCell].Column Then _ Exit Sub With ActiveSheet iHPBs = .HPageBreaks.Count iVPBs = .VPageBreaks.Count lRow = 0 iCol = 0 If iHPBs > 0 Or iVPBs > 0 Then For lRow = iHPBs To 1 Step -1 If .HPageBreaks[lRow].Location.Row

Chủ Đề