首页 > 解决方案 > 你可以创建一个 PDF 并有一个目标路径,如下所示?

问题描述

好的,所以我正在尝试创建一个 PDf 并将其放入以单元格 E10 命名的文件夹中,该文件夹位于 B18 的文件夹旁边。我得到一个“如果没有结束如果编译错误块”我已经尝试了结束和退出语句,但没有运气。

Function Dispatch_PDF() As Boolean  ' Copies sheets into new PDF file for e-mailing
 
    Dim Thissheet As String, ThisFile As String, PathName As String
    Dim SvAs As String
    Dim Tmp         As String
    Dim FldName     As String
    
    ' 1. Create the name you want to search for before starting the search
    ' 2. don't refer to cells by their range names (too cumbersome)
    FldName = Cells(10, 5).Value                          ' actually, it's Cells(10, 5)
    Debug.Print FldName                                     ' check the name
    If Len(FldName) Then
        Tmp = Cells(18, 2).Value
        If Len(Tmp) Then
            FldName = Tmp & "\" & FldName                   ' observe how to add the path separator
            Debug.Print FldName                             ' check the name
            FldName = ActiveWorkbook.path & "\DISPATCHED WORK ORDERS\" & FldName
            Debug.Print FldName
    
    Application.ScreenUpdating = False
 
' Get File Save Name
        Thissheet = ActiveSheet.Name
        ThisFile = ActiveWorkbook.Name
        PathName = ActiveWorkbook.path
        SvAs = PathName & "\DISPATCHED WORK ORDERS\" & FldName & Range("E10").Value & ".pdf"
 
'Set Print Quality
        On Error Resume Next
        ActiveSheet.PageSetup.PrintQuality = 600
        Err.Clear
        On Error GoTo 0
 
' Instruct user how to send
        On Error GoTo RefLibError
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SvAs, Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True
        On Error GoTo 0
    
SaveOnly:
        MsgBox "A copy of this sheet has been successfully saved as a  .pdf  file: " & Chr(13) & Chr(13) & SvAs & _
        "Review the .pdf document. If the document does NOT look good, adjust your printing parameters, and try again."
        
    Dispatch_PDF = True
    GoTo EndMacro
    
RefLibError:
    MsgBox "Unable to save as PDF. Reference library not found."
    Dispatch_PDF = False
EndMacro:
    
End Function

有什么建议么?

标签: excelvba

解决方案


推荐阅读