いま選択しているページだけ印刷(特定のセルのページ番号を取得)

' Printout Current Page
'アクティブなセルのあるページだけ印刷
Public Sub PrintCurrentPage()
    Dim PageNumber As Long
    PageNumber = PageNumberOf(ActiveCell),
   
    s.PrintOut From:= PageNumber , To:=PageNumber
End Sub

'特定のセルのページ番号を取得
'RangeのTopLeftCellのページ番号を取得
Function PageNumberOf(c As Range) As Long
    Dim s As Worksheet
    Set s = c.Worksheet

    Dim ActiveRow As Long, ActiveCol As Long
    ActiveRow = c.Row
    ActiveCol = c.Column
    
    Dim i As Long
    '上から何ページ目
    Dim PageRow As Long
    PageRow = 1
    Dim HPBCount As Long
    HPBCount = s.HPageBreaks.Count
    For i = 1 To HPBCount
        If ActiveRow < s.HPageBreaks(i).Location.Row Then
            Exit For
        Else
            PageRow = PageRow + 1
        End If
    Next
    
    '左から何ページ目
    Dim PageCol As Long
    Dim VPBCount As Long
    VPBCount = s.VPageBreaks.Count
    PageCol = 1
    For i = 1 To VPBCount
        If ActiveCol < s.VPageBreaks(i).Location.Column Then
            Exit For
        Else
            PageCol = PageCol + 1
        End If
    Next

    'ページの印刷方向("左から右"か"上から下"か)によってページ数は変わる
    Dim PageNumber As Long
        If s.PageSetup.Order = xlDownThenOver Then '左端から右へ  ↓\↓\↓\↓
            PageNumber = (s.HPageBreaks.Count + 1) * (PageCol - 1) + PageRow
        Else '上から下
            PageNumber = (s.VPageBreaks.Count + 1) * (PageRow - 1) + PageCol
        End If
    PageNumberOf = PageNumber
End Function