如何在Mac上自动导出PDF?

发布于 2025-02-13 14:26:17 字数 944 浏览 0 评论 0 原文

我们在一个团队中工作。我们中的一些人在PC上,其他人在Mac上。

我想出了此潜水艇自动导出PDF(+通过PubliPosting for命名链接到Excel),它在我的PC上起作用,但在Mac上不起作用。

Sub Export_nom_lot_pdf()
'
' Export_nom_lot_pdf Macro
'
'
Dim UpDir As String
UpDir = ActiveDocument.Path
AwKN = ActiveDocument.Name
SplitAwKN = Split(AwKN, ".")
NomFichier = SplitAwKN(0)
SplitNF = Split(NomFichier, "_")
phase_nom = SplitNF(0)
lot_num = ActiveDocument.MailMerge.DataSource.DataFields(8).Value
lot_nom = ActiveDocument.MailMerge.DataSource.DataFields(9).Value
entreprise_nom = ActiveDocument.MailMerge.DataSource.DataFields(13).Value
'
ChangeFileOpenDirectory UpDir
ActiveDocument.ExportAsFixedFormat OutputFileName:=phase_nom & "_lot-" & lot_num & "_" & lot_nom & "_" & entreprise_nom, ExportFormat:=wdExportFormatPDF
Application.ScreenUpdating = True
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
End Sub 

We work in a team. Some of us on PC, others on MAC.

I came up with this sub for exporting PDFs automatically (+ linked to Excel via publiposting for the naming), which works on my PC but it won't work on MAC.

Sub Export_nom_lot_pdf()
'
' Export_nom_lot_pdf Macro
'
'
Dim UpDir As String
UpDir = ActiveDocument.Path
AwKN = ActiveDocument.Name
SplitAwKN = Split(AwKN, ".")
NomFichier = SplitAwKN(0)
SplitNF = Split(NomFichier, "_")
phase_nom = SplitNF(0)
lot_num = ActiveDocument.MailMerge.DataSource.DataFields(8).Value
lot_nom = ActiveDocument.MailMerge.DataSource.DataFields(9).Value
entreprise_nom = ActiveDocument.MailMerge.DataSource.DataFields(13).Value
'
ChangeFileOpenDirectory UpDir
ActiveDocument.ExportAsFixedFormat OutputFileName:=phase_nom & "_lot-" & lot_num & "_" & lot_nom & "_" & entreprise_nom, ExportFormat:=wdExportFormatPDF
Application.ScreenUpdating = True
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
End Sub 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半城柳色半声笛 2025-02-20 14:26:17

您没有说出错误发生的位置,但是代码中几乎可以肯定不起作用的一件事是呼叫 exportasFixedFormat

如果是这样,可以说这个问题是这个问题即都不<<代码> exportasFixedFormat nor exportasFixedFormat2 似乎在Mac上工作。从那时起,情况似乎没有改变。您可以使用 saveas2 ,例如,

ActiveDocument.SaveAs2 _
  OutputFileName:=phase_nom & "_lot-" & lot_num & "_" & lot_nom & "_" & entreprise_nom, _
  FileFormat:=WdSaveFormat.wdFormatPDF

使用 exportasFixedFormat 时,不允许您使用一些可用的选项。

您的代码中还有其他一些事情可能会引起问题或可能在Windows上引起问题,如果您更改为 saveas2 ,例如

  • ,如果没有保存ActivedOcument,则 Updir 将BE “” ,这将在 ChangeFileOpendirectory 中导致错误。
  • 文件名中可能有特殊字符在Windows上允许使用,但在Mac上不允许
  • 您将扩展名为“ .pdf”添加到名称中。 (我认为实际上不需要,但您应该检查)。

如果您需要在Windows和Mac版本上使用不同的代码,则可以使用“指令”来执行此操作,例如,

#If Mac Then
' put code for the Mac version here
#Else
' put code for all other versions here
#End If

请参见 this 此以获取更多信息。

一次,从Mac上的软件创建PDF的主要方式是打印到该格式。 Mac Word的当前版本还具有与Windows Word中的用户界面选项相等的(例如,将文件发送到Microsoft Service进行转换的选项。记录

我的意见 。在那里有很多差异 - 有时很小,例如在Windows上但不是MAC上的对象属性,有时甚至更大,例如在Mac上未实现的对象,有时甚至更令人困惑的情况,其中某些事物在两个上的工作方式有所不同平台

You do not say where your error occurs, but the one thing in your code that will almost certainly not work is the call to ExportAsFixedFormat.

If so, this question is arguably a duplicate of this question i.e. that neither ExportAsFixedFormat nor ExportAsFixedFormat2 seem to work on Mac. The situation does not seem to have changed since then. You can use SaveAs2 instead, e.g.

ActiveDocument.SaveAs2 _
  OutputFileName:=phase_nom & "_lot-" & lot_num & "_" & lot_nom & "_" & entreprise_nom, _
  FileFormat:=WdSaveFormat.wdFormatPDF

That will not allow you to use some of the options that are available when using ExportAsFixedFormat.

There are some other things in your code that could cause problems or might cause problems on Windows if you change to using SaveAs2, e.g.

  • If the ActiveDocument has not been saved, UpDir will be "", and that will cause an error in ChangeFileOpenDirectory.
  • It is possible that there are special characters in the file name that are allowed on Windows but not on Mac
  • You might need to add the extension ".pdf" to the name. (I do not think it is actually needed but you should check).

If you need to use different code on the Windows and Mac versions, you can use "directives" to do it, e.g.

#If Mac Then
' put code for the Mac version here
#Else
' put code for all other versions here
#End If

See this and this for more information on that.

At one time the main way to create PDFs from software on Mac was to print to that format. The current version of Mac Word also has User Interface options equivalent to the ones in Windows Word (e.g. the option that sends the file to a Microsoft Service for conversion. So I switched on the VBA Macro Recorder and recorded that. But it didn't record anything.

Just my opinion, but if you need to write code that works on both Windows and Mac, you really need to have both types of system available to you. Microsoft's own documentation for the Office object models is primarily based on the Windows version and there are a lot of differences - sometimes quite minor, such as a an object property that's on Windows but not Mac, sometimes larger, such as objects that are not implemented on Mac, and sometimes the more confusing situation where something just works differently on the two platforms.

(Sorry,if you post comments I can't reply to them yet).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文