简体   繁体   English

VBA Excel设置打印区域

[英]VBA excel setting print area

I am setting a print area using named range, since it's a table and it grows. 我正在使用命名范围设置打印区域,因为它是一个表格并且会不断增长。 When I execute, the headings wont print. 当我执行时,标题将不会打印。 How can I adjust this to print the named range(Table3) along with the headers? 如何调整它以打印命名范围(表3)和标题?

I tried; 我试过了; ActiveSheet.PageSetup.PrintArea = Range("Table3{Headers}").Address but only printed the Headers. ActiveSheet.PageSetup.PrintArea = Range("Table3{Headers}").Address但仅打印标题。

Application.Dialogs(xlDialogPrinterSetup).Show
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    Application.PrintCommunication = True
    ActiveSheet.PageSetup.PrintArea = Range("Table3").Address
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup

I want the headers and Table3 to print. 我要打印标题和Table3。

A table is a ListObject . 表是ListObject Use the ListObject.Range property to return the Range that the table refers to (includes headers). 使用ListObject.Range属性可返回表所引用的Range (包括标头)。

Dim myTbl as ListObject
Set myTbl = ThisWorkbook.Sheets("mysheetname").ListObjects("Table3")
...
ThisWorkbook.Sheets("mysheetname").PageSetup.PrintArea = myTbl.Range.Address

Change the sheet name as needed. 根据需要更改工作表名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM