空格检查上一页并在Excel中插入行

时间:2017-01-18 18:44:20

标签: excel vba excel-vba function

我在(A795:O830)中有文本块。它通过分页符与其他页面分开,始终是打印(xls,pdf)文档的最后一页。有时第一页上有很多可用空间,(A795:O830)可以安装在那里。现在它由Page Break完成,并且不会改变。在我的情况下,66行可以放在一页上。

是否有任何宏可以自动检查上一页是否有足够的空白空间(A795:O830)并将其插入那里?

这是我当前的宏:

Sub Remove_color()
    Dim myRange As Range
    Dim cell As Range
    Set myRange = Range("A24:O785")
        For Each cell In myRange
        myRange.Interior.ColorIndex = 0
    Next
End Sub
Sub Hide_empty_cells()
    Set rr = Range("A24:N832")
    For Each cell In rr
    cell.Select
        If cell.HasFormula = True And cell.Value = "" And cell.EntireRow.Hidden = False Then Rows(cell.Row).EntireRow.Hidden = True
    Next cell
End Sub
Sub Save_excel()
    Dim iFileName$, iRow&, iCol&, iCell As Range, iArr
    iFileName = ThisWorkbook.Path & "\New_folder_" & [D5] & "_" & ".xls"
    iArr = Array(1, 3, 4): iCol = UBound(iArr) + 1

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.Calculation = xlManual

    ThisWorkbook.Sheets(2).Copy
    With ActiveWorkbook.ActiveSheet
         .Buttons.Delete '.Shapes("Button 1").Delete
         .UsedRange.Value = .UsedRange.Value
         .SaveAs iFileName, xlExcel8: .Parent.Close
    End With

    Application.Calculation = xlAutomatic
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
Sub Save_pdf()
        ActiveWorkbook.Sheets(2).Select
        ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=ThisWorkbook.Path & "\New_folder_\" & [D5] & "_" & ".pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=No, _
        OpenAfterPublish:=False

End Sub
Sub doitallplease()
Call Remove_color
Call Hide_empty_cells
Call Save_excel
Call Save_pdf
End Sub

0 个答案:

没有答案