excel 2007 vba: how to refer to HPageBreaks

跟風遠走 提交于 2019-12-12 12:17:07

问题


I'm trying to write a macro which can look into the list of horizontal page breaks that a worksheet keeps, and it seems like HPageBreaks should be exactly that. I can add or remove page breaks from it, but I can't seem to isolate the collection itself to look at its contents. Even adding a watch and looking at ActiveSheet.HPageBreaks just brings up a generic looking object with a count field equal to 0 regardless of existing page breaks.

I'm really confused about this now. Is there any way to look into the existing page breaks within a sheet? A listing of what rows they occur on/between would be great.


回答1:


This should get you started:

Sub testing()
    MsgBox "There are " & ActiveSheet.HPageBreaks.Count & " pagebreaks."
    For Each pb In ActiveSheet.HPageBreaks
        MsgBox "a page break lies between rows " & pb.Location.Row - 1 _
            & " and " & pb.Location.Row
    Next
End Sub

Here are some (rather scanty) references.:

http://msdn.microsoft.com/en-us/library/aa661442(office.10).aspx

http://msdn.microsoft.com/en-us/library/aa206426(office.10).aspx



来源:https://stackoverflow.com/questions/2540993/excel-2007-vba-how-to-refer-to-hpagebreaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!