简体   繁体   English

Vba:将 Excel 工作表打印到多个 pdf 页面

[英]Vba: Print an Excel sheet to multiple pdf pages

I'll try to keep this short.我会尽量保持简短。 I'm working on a Excel project and I have to print at the end a single sheet, the problem is the printed PDF is too small, so I've looked up for it in different forums and I found out that I had to turn .FitToPagesTall = 0 In order that the excel worksheet don't get fit to one pdf page.我正在做一个 Excel 项目,我必须在最后打印一张纸,问题是打印的 PDF 太小,所以我在不同的论坛上查找它,我发现我必须转.FitToPagesTall = 0为了使 excel 工作表不适合一个 pdf 页面。 The problem I'm struggling with now is that even if the pdf pages are bigger than before, It still small and It's making it hard to read.我现在正在努力解决的问题是,即使 pdf 页面比以前大,它仍然很小,而且很难阅读。 My idea is to print each 30 rows (for example) in a pdf page (Page1 --> Range("A1:E30"), Page2 --> Range("A31:E60").. etc, you got the idea)我的想法是在 pdf 页面中打印每 30 行(例如)(Page1 --> Range("A1:E30"), Page2 --> Range("A31:E60").. etc,你明白了)

Any ideas how I can do that please?有什么想法我该怎么做吗?

Thanks in advance !提前致谢 !

Update #1: Here's a screen shot of only a slice of my data range更新#1:这是我的数据范围的一部分的屏幕截图在此处输入图像描述

Even if I set the .PrintArea to A:D, it still give the same result.即使我将.PrintArea设置为 A:D,它仍然给出相同的结果。 To rephrase my request: I'm looking for a way to print different ranges in multiple pages.重新表述我的要求:我正在寻找一种在多页中打印不同范围的方法。

thanks everyone for giving me a part out of ur time.感谢大家在你的时间里给了我一部分。

try to adapt the Orientation and fit the data horizontally, something like this : 尝试调整方向并水平拟合数据,如下所示:

With ActiveSheet.PageSetup
    .PrintTitleRows = "$1:$1" 'to repeat your header on each page 
    .CenterHorizontally = True
    .CenterVertically = True
    .Orientation = xlLandscape ' or xlPortrait
    .Zoom = False
    .FitToPagesWide = 1 'fit to wide only
    .FitToPagesTall = 0
End With

EDIT: auto-selection code added编辑:添加了自动选择代码

My understanding of the question: how to print multiple selections from the same worksheet into PDF containing multiple pages (each selection = new page)我对问题的理解:如何将同一工作表中的多个选择打印到包含多个页面的 PDF 中(每个选择=新页面)

Multiple selection (ctlr) & Print Selection多选(ctlr)和打印选择

Range("A1:E30, A31:E60") _ 
    .PrintOut Copies:=1, Collate:=True  'your ranges in the quotes
'prompts user to choose destination where to save to

It is equal to manually selecting multiple ranges (holding ctrl ) and selecting print selection when printing.相当于手动选择多个范围(按住ctrl ),打印时选择print selection

打印选择

Edit - Code added编辑 - 添加代码

If you like the above idea, you might like the following code?如果你喜欢上面的想法,你可能喜欢下面的代码?

It constructs a string , such as: "A1:D30,A31:D60,A61:D90" , which specifies ranges to be selected.它构造一个string ,例如: "A1:D30,A31:D60,A61:D90" ,它指定要选择的范围。 Assumptions is that data is in columns AD and last row can be found in column A. You can specify how many rows to print in my_step .假设数据在 AD 列中,最后一行可以在 A 列中找到。您可以在my_step中指定要打印的行数。

Sub select_and_print()

Dim s_rn, s_range As String
Dim i, my_step As Integer
Dim selections_count As Single

my_step = 30 'how many rows to include on 1 page

'to prevent extra page in some cases:
selections_count = WorksheetFunction.RoundUp((Cells(Rows.Count, 1).End(xlUp).Row / my_step), 0)

'String, which specifies selections in ws, between columns A - D
For i = my_step To selections_count * my_step Step my_step:
    s_rn = "A" & (i - my_step + 1) & ":D" & i
    If i = my_step Then
        s_range = s_rn
    Else
        s_range = s_range + "," + s_rn
    End If
Next i

'selection & print
Range(s_range).PrintOut Copies:=1, Collate:=True 

End Sub

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

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