目标是在Access应用程序中运行此子例程,该应用程序将PDF文档嵌入到新的Excel工作簿中。子文件与文本文件正常工作,但会出现错误“运行时错误'1004':文档未保存。”用PDF文件。 SaveAs方法中的代码中断。为什么一个文件类型嵌入,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
答案 0 :(得分:0)
这适用于嵌入pdf图标/链接,但它也会打开pdf。加重。
ActiveSheet.OLEObjects.Add(Filename:="C:\Users\June\MyStuff\DMV.pdf", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\Installer\{AC76BA86-7AD7-1033-7B44-AB0000000001}\PDFFile_8.ico", _
IconIndex:=0, IconLabel:="whatever you want").Activate
我可以手动保存文件但SaveAs代码用于启用宏的工作簿错误。更加恶化。也许修改你的对象操作代码会起作用。