2014-11-04 123 views
1

更新: 樣本Excel數據我想PDF和PDF文件通常低於 Excel中創建的 - http://i.imgur.com/lnE1VER.jpg PDF - http://i.imgur.com/yNDHFMv.jpgPostScript文件轉換爲PDF格式不工作

的問題似乎是該過程沒有檢測到工作表中的任何內容 - 關於如何「激活」內容的任何建議?

-

我有一個VBA宏轉換爲PDF文件,Excel報表 - 我想複製跨多個工作簿的代碼,但是當我做一些工作簿,而不是人的作品。

代碼如下 - 我將每個工作簿中的四個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 PostScript文件麻煩,其中規定一個文本文件中的工作簿:

%% [注意:清空工作。沒有生成PDF文件。 ] %%

+0

也許你應該鏈接到未能轉換爲PDF – yms 2014-11-04 15:28:38

+0

感謝PostScript文件之一,我已經更新了什麼是由生產的細節後代碼不起作用 – GullitsMullet 2014-11-04 15:50:40

+2

在我看來,像'print'產生一個0Kb(空,就像Distiller產生的文本文件所說的那樣)PostScript文件,這意味着它不包含任何內容,所以不出所料,一個PDF文件。我對VBA一無所知,但我猜想awb.Sheets(「PIN」)是空的。 – KenS 2014-11-04 16:58:16

回答

0

在撕掉我的頭髮並未能找到近6個月的解決方案後,我的同事剛剛發現它 - 我們試圖創建的PDF文件名太長了,我們縮短了,現在工作正常!

我要爲一個午覺

0

首先顯而易見的是:0字節PostScript語言文件不包含圖形,因此Distiller無法將其轉換爲有意義的PDF文件。那麼,爲什麼Postscript語言文件長0字節?

從問題電子表格打印失敗。

以VBA出問題。嘗試通過Excel「打印」菜單項從問題電子表格打印。打印到PostScript和非PostScript打印機。我懷疑這也會失敗。

診斷打印失敗。一旦「打印」菜單項起作用,我懷疑VBA腳本也會。