[算表] VBA輸出PDF於特定次數後發生問題

看板Office作者 (只是過客)時間7年前 (2019/03/17 23:25), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
軟體:OFFICE 版本:2019 64位元版 最近在跑公司資料產製圖表輸出,但無論用「ExportAsFixedFormat」或「Printout」的 方式處理,大約165筆左右就會異常,下方有測試時的錄影紀錄 1.不產出PDF理論上可以跑完全部資料 2019-03-17VBA測試紀錄 https://youtu.be/4NK0B0OHt9U
http://tinyurl.com/y2o5jxzd 2.產出PDF (1)以ExportAsFixedFormat的方式產出的資料較小 2019-03-17VBA測試紀錄ExportAsFixedFormat https://youtu.be/ZtYduSyLqnQ
http://tinyurl.com/y4yrqefq (2)以printout方式產出的資料大約為ExportAsFixedFormat方法的2倍大小 2019-03-17VBA測試紀錄print https://youtu.be/219px5hiU2k
http://tinyurl.com/y2w2s5gs 系統資源不足,無法完整顯示。 http://tinyurl.com/y4s9jyxk 但無論以何種方式,大約執行165筆後就會異常,觀察截圖後 讀取量大小 Printout(178,665) > ExportAsFixedFormat(151,766) > 不產出 PDF(31,057) 寫入量大小 ExportAsFixedFormat(655,688) > Printout(17,874) > 不產出PDF(5,786) 其他I/O大小 Printout(1,190,267) > ExportAsFixedFormat(948,638) > 不產出 PDF(104,833) 記憶體用量 ExportAsFixedFormat(231,952K) > Printout(229,096K) > 不產出 PDF(172,692K) 猜想應該是記憶體使用量的問題,但是不產出PDF下執行到499筆的記憶體量卻不會發生「 系統資源不足,無法完整顯示。」的問題,請問可能是哪個環節出了問題呢?? 下方為轉檔時主要會用到的程式碼 Sub export() Dim FileName As String Dim myFolder$ Dim MyFile As Object Dim i As Integer, filemsg As Integer myFolder = "D:\" For i = 1 To 499 '暫停10秒 If i Mod 50 = 0 Then ThisWorkbook.save End If Application.StatusBar = "目前進度" & i myfilepath = myFolder & FileName & ".pdf" 輸出.ExportAsFixedFormat Type:=xlTypePDF, FileName:=myfilepath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False 'ExportAsFixedFormat方法 '輸出.PrintOut ActivePrinter:="Microsoft Print to PDF", Copies:=1, Collate:=True, IgnorePrintAreas:=False, PrToFilename:=myfilepath 'printout方 法 Application.Wait Now() + TimeValue("00:00:01") Set MyFile = CreateObject("Scripting.FileSystemObject") '檢測檔案大小 Application.Wait Now() + TimeValue("00:00:01") With MyFile.Getfile(myfilepath) filemsg = Round(.Size / 1024) '判斷檔案大小 filesize = "檔案大小:" & filemsg & "KB" If filemsg < 50 Then filelog = "檔案錯誤,強制跳出迴圈" MsgBox (filelog) Exit For End If Set MyFile = Nothing End With Next End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.34.107.203 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1552836343.A.90E.html
文章代碼(AID): #1SZcRtaE (Office)
文章代碼(AID): #1SZcRtaE (Office)