将Excel工作表另存为PDF

安妮·梅特·瑙尔比

作为VBA的绝对新手,我整理了一些代码,这些代码将在Excel工作表中运行,检查其中的所有内容,然后将工作表另存为PDF文件。但是,我在保存部分代码方面遇到了麻烦。我不断收到此行的错误“编译错误:预期:=”:

`Wsa.ExportAsFixedFormat(Type:=xlTypePDF,Filename:=myFile,Quality:=xlQualityStandard,IncludeDocProperties:=True,IgnorePrintAreas:=False, OpenAfterPublish:=False)´

我在这里只是一个完整的n00b吗?

整个过程看起来像这样:

Sub mcrSave()

Dim wsA As Worksheet

Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler

'Check for mandatory fields
If Range("B3").Value = "" Then MsgBox ("Please fill in applicant")
Exit Sub
If Range("C1").Value = "" Then MsgBox ("Please fill in project title")
Exit Sub
If Range("H3").Value = "" Then MsgBox ("Please fill in date of application")
Exit Sub
If Range("C5").Value = "" Then MsgBox ("Please fill in expected cost")
Exit Sub
If Range("C7").Value = "" Then MsgBox ("Please fill in time schedule")
Exit Sub
If Range("B10").Value = "" Then MsgBox ("Please fill in project description")
Exit Sub
If Range("B18").Value = "" Then MsgBox ("Please fill in potential benefits")
Exit Sub
If Range("B26").Value = "" Then MsgBox ("Please fill in potential drawbacks")
Exit Sub
If Range("B34").Value = "" Then MsgBox ("Please fill in internal/external ressources")
Exit Sub



Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "yyyymmdd\_hhmm")

'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
  strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"

'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")

'create default name for savng file
strFile = strName & "_" & strTime & ".pdf"
strPathFile = strPath & strFile

'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename(InitialFileName:=strPathFile, FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Select Folder and FileName to save")

'export to PDF if a folder was selected
If myFile <> "False" Then
    Wsa.ExportAsFixedFormat(Type:=xlTypePDF,Filename:=myFile,Quality:=xlQualityStandard,IncludeDocProperties:=True,IgnorePrintAreas:=False, OpenAfterPublish:=False)
    'confirmation message with file info
    MsgBox "PDF file has been created: " & vbCrLf & myFile
End If

exitHandler:
    Exit Sub
errHandler:
    MsgBox "Could not create PDF file"
    Resume exitHandler

End Sub
CLR

将导出命令更改为以下内容:

Wsa.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

另外,您需要更改您的“强制”字段检查,以使每个检查都类似于:

If Range("B3").Value = "" Then
   MsgBox ("Please fill in applicant")
   Exit Sub
End If

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我可以通过ClosedXML将EXCEL工作表另存为CSV吗?

通过Excel将pptx另存为pdf

VBA将单个工作表另存为CSV(不是整个工作簿)

动态将段落另存为PDF?

使用Office.Interop.Excel将文件另存为PDF / A

使用单元格值作为标题将工作表另存为新工作簿

如何使用Excel宏将多个网页另存为pdf文件或屏幕截图?

将.maf文件另存为表

将工作表另存为CSV-忽略隐藏的工作表或带有宏的工作表

将Excel工作表另存为.txt

如何在Excel VBA中将每个工作表的首页另存为PDF

关于将活动表另存为新工作表的问题

使用新输入将单个excel工作表另存为新的excel文件

将Excel工作簿的单独工作表另存为PDF

将油量图另存为PDF

将Excel工作表另存为JSON文件

将pdf文件另存为blob

将excel另存为pdf,将文件名另存为变量值

Excel工作簿另存为.pdf

将工作表另存为单独的PDF:“发出API请求时必须包括API令牌。”

VBA仅将可视表另存为工作簿

如何将Excel工作簿中的所有工作表另存为一个文本文件?

将另一个工作表另存为pdf,同时循环浏览下拉菜单,而不显示每个项目的“另存为”框

将多个 Excel 工作表另存为 PDF

将带有图形的工作表另存为 PDF

循环遍历 excel 文件中的工作表并另存为 csv 文件的问题

Excel VBA - 使用特定工作表中的内容另存为文件

VBA 将工作表另存为特定路径中的工作簿

如何将多个功能应用于所有工作表,然后另存为一个 Excel 工作簿