excel - VBA Script to Create PDF from Excel Goes to Printer and Doesn't Export File
问题描述
I have the following code which worked well on a Windows machine but since I moved to a MacBook, it is causing me problems:
With ActiveSheet
Fname = "SalarySlip-" + employeeName + "-" + month + ".pdf"
.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
salarySlipsFolderPath & Fname, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False,
OpenAfterPublish:=False
End With
Rather than exporting as a PDF file (it worked like that on Windows), a request is sent to the printer to print the file. What am I missing here?
I am using MacOS Catalina 10.15.4 running MS Excel for MAC version 16.40.
解决方案
如果您用作变量的一个单元格值包含斜杠(例如,日期month
为 2020/01/01),则 PDF 文件的命名过程将失败并将其发送到打印机。我经历了几个绝望的小时......
并尝试
ChDir "/" & ActiveWorkbook.Path
Sub
作为and的第一行
fileName:= _
"/" & salarySlipsFolderPath & Fname, Quality:=xlQualityStandard, _
作为文件名。一"/"
开始它对我有用。
推荐阅读
- python - Gensim 训练 word2vec 和 Fasttext
- scala - 使用超类型过滤 HList
- java - Java字符串分隔数列
- java - teiid importer.schemaPattern 属性不起作用
- html - data-val-regex-pattern 无法否定某些特定字符
- java - 如何为可选流中的列表映射索引 0 处的值
- datetime - Flutter 日期时间解析
- java - 我如何知道哪些第三方依赖项在本机模式下与 Quarkus 兼容?
- sql - SQL/ORACLE 查询练习 18c
- node.js - Express + PassportJS 无法读取 flash 消息