Print Current Page Only Macro

  • Thread starter Thread starter vschlen
  • Start date Start date
V

vschlen

I am trying to come up with a macro with the ability to print th
current page. It has become a big need within my company and will b
a real time saver. Is there a way to search for the active cell an
then print the current page it is in? In other words, by placin
your cursor on the page you want to print, you could then run th
print current page macro
 
Hi
SUB print_current()
ActiveSheet.PrintOut
end sub

But why don't you sue the print icon in the toolbar. AFAIK this only
prints the current selected sheet(s)

HTH
Frank
 
don't forget -- the SHEET and the CURRENT PAGE are not necessarily the
same. Some worksheets may print to 20, 30 or more pages. Defining the
print area is also a useful tool -- but needs to be reset to each different
area as needed.

Kate in MN
 
If I have understood you correctly, this
code will do the job.
Place the cursor in a cell and run the sub,
and the page containing the active cell
will be printed.

Sub PrintPageContainingCursor()
'Leo Heuser, 4 Feb. 2004
Dim Hpb As HPageBreak
Dim HorizPagebreak As Long
Dim NumberOfHorizPages As Long
Dim NumberOfVertiPages As Long
Dim PageNumber As Long
Dim Vpb As VPageBreak
Dim VertiPagebreak As Long

With ActiveSheet
NumberOfHorizPages = .HPageBreaks.Count + 1
NumberOfVertiPages = .VPageBreaks.Count + 1

For Each Vpb In .VPageBreaks
If Vpb.Location.Column < ActiveCell.Column Then
VertiPagebreak = VertiPagebreak + 1
End If
Next Vpb

For Each Hpb In .HPageBreaks
If Hpb.Location.Row < ActiveCell.Row Then
HorizPagebreak = HorizPagebreak + 1
End If
Next Hpb

If .PageSetup.Order = xlOverThenDown Then
PageNumber = NumberOfVertiPages * _
HorizPagebreak + VertiPagebreak + 1
Else
PageNumber = NumberOfHorizPages * _
VertiPagebreak + HorizPagebreak + 1
End If

.PrintOut , from:=PageNumber, to:=PageNumber, copies:=1
End With
End Sub
 
Back
Top