gpt4 book ai didi

vba - 使用 VBA 将两个不同工作表上的多个范围保存为 PDF

转载 作者:行者123 更新时间:2023-12-04 21:54:45 26 4
gpt4 key购买 nike

我需要将这两个表格和范围合并到一个 PDF 中。我已经尝试了所有我能找到的宏,但它们都不起作用。这是我正在使用的宏,除了在一个文档中组合的范围外,它都可以工作

Private Sub SaveLHForms()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

FormName = Sheets("SETUP").Range("B2").Value & " " & ActiveSheet.Range("S1") & ".pdf"

ChDir DesktopAddress
Sheets("Lienholder Docs").Range("A45:I151").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
FormName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Sheets("Settlement Letters").Range("A47:I92").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
FormName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

最佳答案

首先需要在设置后创建一个pdf文档打印区在每张纸的页面设置中。

Sub test()
Dim path As String
Dim myArr As Variant, a As Variant
Dim rngArr As Variant
Dim Ws As Worksheet
Dim formName As String
Dim i As Integer

formName = Sheets("SETUP").Range("B2").Value & " " & ActiveSheet.Range("S1") & ".pdf"

myArr = Array("Lienholder Docs", "Settlement Letters") '<~~ Sheet name
rngArr = Array("A45:I151", "A47:I92") '<~~ print area address

For i = 0 To UBound(myArr)
Set Ws = Sheets(myArr(i))
With Ws
.PageSetup.PrintArea = .Range(rngArr(i)).Address
End With
Next a
Sheets(myArr).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
formName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False


End Sub

关于vba - 使用 VBA 将两个不同工作表上的多个范围保存为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47099711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com