excel - 你可以创建一个 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
有什么建议么?
解决方案
推荐阅读
- javascript - 为什么 Object.keys() 方法没有添加到 Object.prototype 中?
- javascript - 为什么不把道具传给孩子?
- python - Flask-Admin:分配前引用的局部变量“admin”
- hadoop - 无法在 Windows 10 上找到或加载主类 org.apache.hadoop.util.RunJar
- hive - 如何使用 Hive 处理所有 Hbase 数据
- rust - 为什么通过提取方法进行重构会触发借用检查器错误?
- python - 使用枕头的图像处理代码中的问题
- javascript - 图像数组中的 foreach 元素
- linux - 检查 linux 上活动的任何屏幕会话
- jquery - Angular5 jQuery 指令 - 导入期间未定义 UI