我正在从事一个使工资自动化的项目,并且已经开发了几个Macros,但是在最后一步遇到了麻烦。我正在将数据从一个工作簿复制到另一个工作簿,以便将时间表纸附加到发票纸上。然后,我将自动创建PDF,当我创建PDF时,它们会缩小以适合我所附的较大页面。我已插入一个手动分页符,以在PDF中创建两个单独的页面,但是PDF仍在缩小第一页并将其不适合整页。有没有一种方法可以在分页符之前进行缩放,以使第一页适合整个PDF尺寸?
我尝试手动更改PDF格式,更改打印预览等。
Sub Excel_to_PDF()
Dim Path As String
Dim filename As String
Dim ws As Worksheet
Dim nm As String
For Each ws In Worksheets
If ws.Visible = xlSheetVisible Then
ws.Select
nm = ws.Name
ActiveSheet.Rows(44).PageBreak = xlPageBreakManual
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:="C:\Users\rober\Desktop\Invoices\" & nm & "-" & ActiveSheet.Range("K6").Value & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next ws
Dim ZoomRng As Range
Set ZoomRng = Range("A1:M43")
ZoomRng.Select
ActiveWindow.Zoom = True
End Sub
我希望将PDF分为两页。第44行之前的第一页,之后的第二页。那不是问题。该宏适用于此。我需要的是缩放第44行之前的工作表,并且不缩放以适合与第二个工作表相同的尺寸。第一页来自A1:L43,第二页来自A50:AC110。因此,第一张纸会缩小,我希望将其放大。
答案 0 :(得分:0)
尝试一下,我认为变焦位置错误。
Sub Excel_to_PDF()
Dim Path As String
Dim filename As String
Dim ws As Worksheet
Dim nm As String
For Each ws In Worksheets
If ws.Visible = xlSheetVisible Then
ws.Select
nm = ws.Name
Dim ZoomRng As Range
Set ZoomRng = Range("A1:M43")
ZoomRng.Select
ActiveWindow.Zoom = True
ActiveSheet.Rows(44).PageBreak = xlPageBreakManual
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:="C:\Users\rober\Desktop\Invoices\" & nm & "-" & ActiveSheet.Range("K6").Value & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next ws
End Sub