Thread: GO TO PAGE
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
LenB LenB is offline
external usenet poster
 
Posts: 25
Default GO TO PAGE

Hi.
You can do it with this macro, and for convenience assign it to a key,
for example ctrl + w.

Below is the code. I tested it in Excel 2002, but I think it will work
in Excel97 or newer. You need to paste it into a code module. For
those new to this, here's how, assuming there are no code modules already.

1. First save a backup copy of your spreadsheet just in case.
2. Press Alt + F11 to get the VB editor.
3. In the tree on the right (the project explorer), right click on the
line saying VBAProject(<your file name here.xls)
4. Insert Module. You now have a Module1 if there wasn't one before.
5. Double click on Module1 to open a code window.
6. Paste the complete code below starting from Sub GotoPage(), and
ending with End Sub
7. Back in Excel, press Alt + F8 to get the macro list. (the same as
Tools Macro Macros.)
8. Single Click on GotoPage, then click "Options". Select your shortcut
key (Ctrl + whatever). Don't use one that Excel already uses. Click
OK. Click "Cancel" to close the macro list.
9. Save the spreadsheet.

Macro security must be set to low or medium to execute the macro. I
suggest medium.

If you want to use it on multiple workbooks, you can save it in a
personal macro workbook, personal.xls, so it is always loads with Excel.

When on your worksheet, press your shortcut and it asks for a page
number and should take you there. It seems to need an active printer to
calculate the pages so if Excel hangs, it probably can't find the printer.

Sub GotoPage()
'Asks for a page number, then goes to the top left cell
' of that page number on the active sheet.

'Seems to need an active printer too. If it seems to
' stop responding, make sure it can find the printer.

Dim lngPage As Long
Dim lngPageColumnCount As Long
Dim lngPageRowCount As Long
Dim lngPageCount As Long
Dim lngPageRow As Long
Dim lngPageColumn As Long
Dim intView As Integer 'the view, either normal or page break

lngPageRowCount = ActiveSheet.HPageBreaks.Count + 1
lngPageColumnCount = ActiveSheet.VPageBreaks.Count + 1
lngPageCount = lngPageRowCount * (lngPageColumnCount)

intView = ActiveWindow.View 'save the view

'need to go to page break to count pages
ActiveWindow.View = xlPageBreakPreview

lngPage = InputBox("Enter the page number, 1 to" & _
Str(lngPageCount), " Goto Page")

If lngPage < 2 Then
'first page, don't calculate it.
Range("a1").Activate
ActiveWindow.View = xlNormalView
Exit Sub
End If

If lngPage lngPageCount Then
lngPage = lngPageCount
End If

'calc the page column and row
lngPageColumn = Int((lngPage - 1) / lngPageRowCount) + 1
lngPageRow = ((lngPage - 1) Mod lngPageRowCount) + 1

'activate the top of the selected page
If lngPageColumn 1 And lngPageRow 1 Then
Cells(ActiveSheet.HPageBreaks(lngPageRow - 1).Location.Row, _
ActiveSheet.VPageBreaks(lngPageColumn - 1) _
.Location.Column).Activate
ElseIf lngPageColumn = 1 And lngPageRow 1 Then
'first column
Cells(ActiveSheet.HPageBreaks(lngPageRow - 1). _
Location.Row, 1).Activate
Else
'first row
Cells(1, ActiveSheet.VPageBreaks(lngPageColumn - 1). _
Location.Column).Activate
End If
'restore the view
ActiveWindow.View = intView

End Sub


Spikey wrote:
I know my Page Numbers. How do I "Go To Page Number" <n ?
You can do this in other products - like Acrobat Reader, Does anyone know
how to do it in MS Excel Please? Im using Excel 2003.

Thanks...