我有一个 MS Access VBA 代码,它生成一个如下所示的 Excel 电子表格,我需要从中输出分页符:
进入这个:
在 MS Access VBA 中以编程方式。
我已经尝试了一堆代码(见下面的片段),但不知何故,它们都没有成功,甚至没有丝毫改变。
代码片段#1)
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.ResetAllPageBreaks
i = 1
If ActiveSheet.HPageBreaks.Count > 0 Then
Do
Set ActiveSheet.HPageBreaks(i).Location = Range("A" & (i * 70) + 1)
If i = ActiveSheet.HPageBreaks.Count Then Exit Do
i = i + 1
Loop
End If
Do Until Cells((i * 70) + 3, 1).Value = ""
ActiveSheet.HPageBreaks.Add Before:=Range("a" & (i * 73) + 1)
i = i + 1
Loop
ActiveWindow.View = xlNormalView
代码片段#2)
Dim Rng As Excel.Range
Set Rng = xls.Rows("1:75")
Rng(75).PageBreak = -4135
代码片段#3)
xls.HPageBreaks.Add Before:=xls.Cells(73, 1)
对此的任何帮助都将受到高度赞赏。非常感谢! :)
最佳答案
我不太了解您的片段,但是根据屏幕截图,您想将其打印在包含所有内容的页面上。像这样的东西在 excel 中将打印区域设置为 1 页 x 1 页 -
Sub breaks()
Dim rLastCol As Long
Dim rLastRow As Long
With ActiveSheet
rLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
rLastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
With .PageSetup
.PrintArea = Range("A1", Cells(rLastRow, rLastCol)).Address
.FitToPagesWide = 1
.FitToPagesTall = False
End With
End With
End Sub
当然,这使用了 A 列和第 1 行中最后使用的单元格,因此最右下角的非空白单元格。
关于excel - 如何从 MS Access 2003 VBA 操作 MS Excel 分页符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26097446/