【问题标题】:VBA Insert page break where cell is specified valueVBA在单元格指定值的地方插入分页符
【发布时间】:2015-07-28 16:13:33
【问题描述】:

我需要在指定值的每个单元格之后在工作表上插入多个分页符。我有一段代码,但目前没有任何反应

Statement.Activate
Dim c As Range
Dim FirstAddress As String

Set c = Columns("A").Find(What:="Please enter your Client Ref  on the reverse", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
If Not c Is Nothing Then
FirstAddress = c.Address

Do
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(1)
Set c = Columns("A").FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If

谁能明白为什么这不起作用?

【问题讨论】:

  • 请检查您在查找中插入的字符串:您的代码对我有用! (但我搜索了“asdf”)

标签: vba page-break


【解决方案1】:

尝试只循环行。

    Dim ws As Excel.Worksheet
    Dim lRow As Long

    lRow = 1
    Set ws = Application.ActiveSheet

    'Loop through and record what is in the first column
    Do While lRow <= ws.UsedRange.Rows.count

        if ws.Range("A" & lRow) = "Please enter your Client Ref  on the reverse" then
            ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(1)
        End if

        lRow = lRow + 1
        ws.Range("A" & lRow).Activate
    Loop

【讨论】:

  • 这给了我一个运行时错误 424 'Object Required' 在 ActiveWindow.... 行上?
【解决方案2】:

发现问题!我已将打印设置为“全部在一页上”。

【讨论】:

    猜你喜欢
    • 2022-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多