|
如题,我的获取单元格的当前页码的代码有问题,一直都是第一页。
Public Function GetCurPage(x As Range) As Integer
'获取某单元格的当前页
'Dim p, k
Dim curpage As Integer
Set sht = ActiveSheet
For p = 1 To HBreaks
If sht.HPageBreaks(p).Location.Row > x.Row Then Exit For
Next
For k = 1 To VBreaks
If sht.VPageBreaks(k).Location.Column > x.Column Then Exit For
Next
If sht.PageSetup.Order = xlOverThenDown Then
curpage = (p - 1) * (VBreaks + 1) + k '当前页的页数
Else
curpage = (k - 1) * (HBreaks + 1) + p '当前页的页数
MsgBox "Total Currunt pages = " & curpage
End If
Application.Volatile
GetCurPage = curpage
End Function
调用的时候是这样的:
Do While Worksheets("Sheet1").Range("A" & m) = Worksheets("Sheet1").Range("A" & n) _
And GetCurPage(Worksheets("Sheet1").Range("A" & m)) = GetCurPage(Worksheets("Sheet1").Range("A" & n))
为什么会出现这样的情况,问题出在哪儿?
|
|