目標是在Access應用程序中運行此子例程,該應用程序將PDF文檔嵌入到新的Excel工作簿中。該子工作正常與文本文件,但會給出錯誤「運行時錯誤'1004':文檔未保存。」與一個PDF文件。代碼在SaveAs方法中斷。爲什麼一個文件類型嵌入,並且PDF文件類型不起作用?任何幫助將不勝感激。將PDF嵌入到電子表格中
Sub SavePDFInWorkBook()
Dim xlObj As New Excel.Application ' Excel application
Dim wbkObj As Excel.workbook ' workbook object
Dim wstObj As Excel.Worksheet ' worksheet object
Dim oleObj As Excel.OLEObject ' embeded object
Dim EmbedFile, MyWbk As String
MyWbk = "M:\SS\DD\Projects\cash_dep2000\TEST.xlsx"
EmbedFile = "M:\SS\DD\Projects\cash_dep2000\DaytonFreight.pdf"
Set wbkObj = xlObj.Workbooks.Add ' workbook is added in open condition in memory
Set wstObj = wbkObj.Worksheets(1) ' workbook is created with one worksheet
Set oleObj = wstObj.OLEObjects.Add(, EmbedFile, False, True)
wbkObj.SaveAs (MyWbk) ' saves workbook to folder
wbkObj.Close ' closes workbook in folder
Set oleObj = Nothing
Set wstObj = Nothing
Set wbkObj = Nothing
Set xlObj = Nothing
MsgBox ("Test Complete")
End Sub
經過測試的代碼。嵌入pdf時也沒有獲取文件來保存。圖像實際上並未添加到工作表中,只是一個帶有圖像名稱的框,除了pdf類型,只是一個很大的空框和沒有文件名。這些是實際文件的鏈接。這是你想要的嗎? PDF鏈接的作品,只是不會保存文件。 – June7