میشل یک کاربرگ طولانی دارد که با آن کار می کند. هنگامی که او از پیش نمایش چاپ برای کاربرگ استفاده می کند، صفحه نشان داده شده در گفتگوی پیش نمایش چاپ همیشه اولین صفحه است. میشل از خود می پرسد که آیا راهی وجود دارد که پیش نمایش چاپ به طور خودکار صفحه کاری را که روی آن کار می کند نشان دهد.
یکی از راه های نزدیک شدن به این مشکل این است که با مناطق چاپی کار کنید. اگر ناحیه صفحه کاری را که روی آن کار می کنید انتخاب کنید و سپس ناحیه چاپ را برابر با انتخاب خود تنظیم کنید، در این صورت وقتی پیش نمایش چاپ را نمایش می دهید، باید فقط آن ناحیه چاپ را ببینید.
اگر این خواسته شما را برآورده نمی کند، ممکن است فکر کنید که می توانید به استفاده از ماکرو متوسل شوید. در اینجا یک نمونه ماکرو وجود دارد که ممکن است این کار را برای شما انجام دهد:
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
This macro is actually a variation on any number of macros you could find with some sleuthing on the Internet. There are two key parts to it—first the macro figures out which "page" you are on in the worksheet, and then it uses the .PrintOut method with the Preview parameter set to True, resulting in Print Preview being invoked.
One some worksheets this macro may work great, but it is quite fickle in whether it will work or not. In most of my testing, I was not able to get it to work, unless I used very small worksheets. (In other words, very few rows and columns.) If you run it on a large worksheet, youll quickly see that you get a "Subscript Out of Range" error in the loop that examines members of the .HPageBreaks collection. How this could happen when you arent using a member that is out of range (lRow never varies outside the value returned by the .Count property) is baffling.
It seems to be a problem that Microsoft acknowledges, though. In fact, it is a problem they have acknowledged, yet never fixed, for years:
https://support.microsoft.com/en-us/help/210663/
The suggested solution on the web page doesnt really work, though. So, we are stuck with a macro that only works reliably on worksheets where you wouldnt need to calculate the page number because you are only working with a single page. Aargh!
The bottom line is that a macro-based approach may—for the foreseeable future—not be viable for Michelles needs. That leaves us with just the print-area approach, described at the beginning of this tip.