【发布时间】: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