excel - 如何从 MS Access 2003 VBA 操作 MS Excel 分页符

标签 excel vba ms-access

我有一个 MS Access VBA 代码,它生成一个如下所示的 Excel 电子表格,我需要从中输出分页符:
Wrong output

进入这个:

supposed output

在 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/

相关文章:

excel - Magento:将产品导出到 csv 或 excel

excel - 光标进入单元格时执行 Action

excel - Excel复制粘贴区域不同

vba - 如何在 VBA 过程中使用 optional 数组参数?

php - xlsb 文件下载不可读的内容错误与 ms excel 2007

vba - VBA匹配和查找错误: No matching type & Undefined Error

c# - 标签从数据库中放入随机值 C#

python - 如何使用 excelwriter 将标题中的文本换行?

sql - 关于多个内连接查询的帮助

ms-access - 3 个表上的内连接不起作用