【问题标题】:Converting postscript file to pdf not working将postscript文件转换为pdf不起作用
【发布时间】:2023-03-27 17:42:01
【问题描述】:

更新: 我正在尝试 pdf 的 excel 数据示例和通常在下面创建的 pdf 文件 Excel - http://i.imgur.com/lnE1VER.jpg PDF - http://i.imgur.com/yNDHFMv.jpg

问题似乎是该过程未检测到工作表中的任何内容 - 关于如何“激活”内容的任何建议?

-

我有一个 VBA 宏,可以将 Excel 报告转换为 PDF 文件 - 我想在多个工作簿中复制代码,但是当我这样做时,它可以在某些工作簿中工作,而不是在其他工作簿中。

代码如下 - 我将每个工作簿中的四个 Const 值更新为每个工作簿的相关单元格/值,并且我检查了每个工作簿中是否选择了相同的引用。

当我运行代码时,它会循环遍历,更改索引单元格并生成包含新数据的 PDF。在其中一个工作簿中,虽然没有创建 PDF,但我已经逐步完成了代码,它会创建 postscript 文件,但不会将其转换为 PDF。

Public Sub ExportGraphs()

Const indexCell = "B55"
Const totalCell = "D55"
Const authorityName = "B5"
Const fileName = "Civic cultural and community venues performance indicator standings report 2013-14 - "

Application.ScreenUpdating = False
Application.ShowWindowsInTaskbar = False
Application.DisplayAlerts = False
Application.EnableEvents = False

Dim i As Integer

Dim awb As Workbook
Set awb = ThisWorkbook

Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller

For i = 1 To awb.Worksheets("PIN").Range(totalCell).Value

awb.Worksheets("PIN").Range(indexCell).Value = i

Dim strGraphLoc, strPIN As String

strPIN = awb.Sheets("PIN").Range(authorityName).Value & " " &   awb.Worksheets("PIN").Range("B6").Value

strGraphLoc = awb.Path & "/"

Dim PSFileName As String
Dim PDFFileName As String

PSFileName = strGraphLoc & fileName & strPIN & ".ps"
PDFFileName = strGraphLoc & fileName & strPIN & ".pdf"

'Print the Excel range to the postscript file
awb.Sheets("PIN").PrintOut copies:=1, from:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, prtofilename:=PSFileName

'Convert the postscript file to .pdf

myPDF.FileToPDF PSFileName, PDFFileName, ""

Kill PSFileName
Kill strGraphLoc & fileName & strPIN & ".log"

Next i

Set myPDF = Nothing

Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.ShowWindowsInTaskbar = True
Application.EnableEvents = True

End Sub

任何帮助将不胜感激,我一生都无法弄清楚为什么它在某些方面有效,而在其他方面无效。

在我遇到问题的工作簿中,创建了一个 0kb 后记文件和一个文本文件,其中说明:

%%[ 警告:空作业。没有生成 PDF 文件。 ] %%

【问题讨论】:

  • 也许您应该添加一个链接,指向无法转换为 PDF 的 postscript 文件之一
  • 谢谢,我已经更新了帖子,详细说明了不起作用的代码所产生的内容
  • 在我看来,您的“打印”正在生成 0Kb(空,正如 Distiller 生成的文本文件所说)PostScript 文件,这意味着它不包含任何内容,因此不出所料,无法转换到 PDF 文件。我对 VBA 一无所知,但我猜 awb.Sheets("PIN") 是空的。
  • 我在尝试导出无法获取内容的图表时遇到了类似的问题,工作表中肯定有内容,附件是我正在尝试的 Excel 工作表示例转换为 pdf 和通常由 VBA 生成的 pdf 文件样本 - excel 表:imgur.com/lnE1VER。 pdf样本:imgur.com/yNDHFMv.

标签: excel vba pdf postscript


【解决方案1】:

首先显而易见:0 字节 PostScript 语言文件不包含图形,因此 Distiller 无法将其转换为有意义的 PDF 文件。那么,为什么 Postscript 语言文件是 0 字节长呢?

从有问题的电子表格中打印失败。

解决 VBA 问题。尝试通过 Excel 的“打印”菜单项从问题电子表格打印。打印到 PostScript 和非 PostScript 打印机。我怀疑这也会失败。

诊断打印失败。一旦“打印”菜单项起作用,我怀疑 VBA 脚本也会起作用。

【讨论】:

    【解决方案2】:

    在撕掉我的头发并且近 6 个月未能找到解决方案后,我的同事刚刚怀疑它 - 我们试图创建的 PDF 的文件名太长,我们缩短了它现在可以正常工作了!

    我要躺下

    【讨论】:

      猜你喜欢
      • 2011-03-30
      • 2016-11-07
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2016-01-19
      • 2017-04-07
      • 2019-11-24
      • 1970-01-01
      相关资源
      最近更新 更多