vba 找出哪一行有水平打印选框线
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9301619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find what row has horizontal print marquee line
提问by M M
This is molasses slow (and doesn't work on fresh sheets):
这是糖蜜缓慢(并且不适用于新床单):
Sub Test()
With Sheets("Sheet1")
.Select
For n = 1 To 1000
If .Rows(n).PageBreak <> xlPageBreakNone Then MsgBox n
If n = 100 Then Exit Sub
Next
End With
End Sub
回答by chris neilsen
If what you want to do is to find the row of the first page break on a sheet, try this
如果您想要做的是在工作表上找到第一个分页符的行,请尝试此操作
Sub WhereIsPageBreak()
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
With ws.HPageBreaks
If .Count > 0 Then
MsgBox .Item(1).Location.Row
Else
MsgBox "No Page Breaks on this Sheet"
End If
End With
End Sub
回答by Siddharth Rout
IF you want to exit when n= 100 then why the loop till 1000? Also when you open a fresh workbook or use the code on a fresh sheet, you will never find the pagebreak as there will be none. If by "fresh" you mean a workbook which already has a pagebreak inserted then your code will still work.
如果您想在 n= 100 时退出,那么为什么要循环到 1000?此外,当您打开新工作簿或在新工作表上使用代码时,您将永远找不到分页符,因为根本找不到。如果“新鲜”是指已经插入分页符的工作簿,那么您的代码仍然可以工作。
Sub Sample()
For n = 1 To 100
If Sheets("Sheet1").Rows(n).PageBreak <> xlPageBreakNone Then MsgBox n
Next
End Sub