VBA,分页符预览,xlpagebreakpreview

时间:2018-10-22 19:01:31

标签: excel vba excel-vba

我想通过Vba自动设置分页预览。 我已经尝试过了,但是得到Unable to set Pagebreak Property of the range Class

Worksheets("Stack").Range("A2:M33").PageBreak = xlPageBreakManual

有人可以帮我放入此分页符/分页符预览吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

我知道已经晚了两年,但是请不要忘记这个答案。我做了以下事情:

Dim WSh As Worksheet, Rng1 As Range, Rng2 As Range

Set WSh = Sheets("Stack")
    Set Rng1 = Range("A5")
    Set Rng2 = Range("N34")

WSh.ResetAllPageBreaks
    'From
    If Rng1.Row <> 1 Then WSh.HPageBreaks.Add before:=Rng1
    If Rng1.Column <> 1 Then WSh.VPageBreaks.Add before:=Rng2
    'To
    WSh.HPageBreaks.Add before:=Rng2
    WSh.VPageBreaks.Add before:=Rng2

行得通。您只需要在管理列“ A”或行“ 1”时确保进行一些处理,但是可以通过几个If轻松地将其分类。