简体   繁体   English

选择选定单元格的特定区域为 PDF,然后在工作表中使用 VBA 进行打印

[英]Select a specific area of selected cells to PDF then print using VBA in a worksheet

i have this worksheet called Test.我有一个名为 Test 的工作表。 In that worksheet i want to export to pdf then print cells G1 to cells H17.在该工作表中,我想导出为 pdf,然后将单元格 G1 打印到单元格 H17。 Next i want to print G1 to cells I17 skipping column H meaning without column H. In another word column G is kind of like the header and the columns that follow the result.接下来我想将 G1 打印到单元格 I17 跳过 H 列,意思是没有 H 列。换句话说,G 列有点像标题和结果后面的列。 So print Header column+ results column and so on until column CM.所以打印标题列+结果列等等,直到列CM。 Below each printing page i want to also export to pdf column C18, column D18 and Column H18 if cells I18 to cells I27=500.在每个打印页面下方,如果单元格 I18 到单元格 I27=500,我还想导出到 pdf 列 C18、列 D18 和列 H18。 I started the code but couldn't go on to finish it since i am not really versed in vba我开始编写代码但无法继续完成它,因为我不是很精通 vba

Sub SetPrintArea()
   Dim ws As Worksheet
   Dim x As Long, result As Boolean
   result = True
For x = 18 To 128
   If Worksheets("AR-MD").Range("H" & x).Value <> ActiveSheet.Cells(8, 19).Value Then
       result = False
   End If
   If Not result Then Exit For
Next x
    
Set ws = ThisWorkbook.Sheets("AR-MD")


ws.PageSetup.PrintArea = Union(ws.Range("g1:g17"), ws.Range("i1:i17"),ws.Range("Result").Address

End Sub


I want to be able to print the result condition but i dont know how to include it in the statement

使用Union方法:

ws.PageSetup.PrintArea = Union(ws.Range("g1:g17"), ws.Range("i1:i17")).Address

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

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