cancel
Showing results for 
Search instead for 
Did you mean: 

Embed PDF file as OLE Object in Excel

RachanaA
Level 3

Hello.

I am trying to embed PDF as an OLE object in Excel via Blue Prism. Any leads would be helpful. Thanks in advance for your time and suggestions.

I am using regular Excel object to create instance, open workbook, activating required worksheet and then attempting to add PDF file using the below code but getting error as “Add method of OLEObjects class failed”

Tested with the ClassType:= “Acrobat.Document.DC” as well

Dim excelApp As Object

Dim workSheet As Object

Dim range As Object

Dim pdfPath As String

excelApp = GetInstance(Handle)

workSheet = excelApp.ActiveSheet

pdfPath = "C:\path\file.pdf"

range = workSheet.Range(“A1”)

workSheet.OLEObjects.Add( _

    ClassType:="AcroExch.Document", _

    FileName:=pdfPath, _

    Link:=False, _

    DisplayAsIcon:=True, _

    IconLabel:="Embedded PDF")

 

Thanks,

1 BEST ANSWER

Helpful Answers

Hi @RachanaA ,

You can try the following approach in a separate action page in your business object:

1) Create a business object named, 'Insert PDF' with following arguments:

devneetmohanty07_0-1739310590272.png

 

2) Create a code stage with the following arguments and code:

devneetmohanty07_1-1739310623870.pngdevneetmohanty07_2-1739310630587.png

Dim wb, excel, range As Object

Try

wb = GetWorkbook(Handle, Workbook)
excel = wb.Application
excel.ActiveSheet.OLEObjects.Add(Filename:=PDFFilePath, Link:=False, DisplayAsIcon:=True, IconFileName:=PDFApplicationPath, IconIndex:=0, IconLabel:="Passport.pdf")

Success = True

Catch e As Exception
	Success = False
	Message = e.Message
Finally
	wb = Nothing
	excel = Nothing
	range = Nothing
End Try

3) Your workflow should look something like this:

devneetmohanty07_3-1739310671765.png

4) Pass the proper arguments for the PDF file path which is your actual file path and your adobe application path and it should work as you can see below:

devneetmohanty07_4-1739310739794.png

 

Let me know if you have any further doubts. Thanks for posting your query in the community.

 

---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

View answer in original post

2 REPLIES 2

Hi @RachanaA ,

You can try the following approach in a separate action page in your business object:

1) Create a business object named, 'Insert PDF' with following arguments:

devneetmohanty07_0-1739310590272.png

 

2) Create a code stage with the following arguments and code:

devneetmohanty07_1-1739310623870.pngdevneetmohanty07_2-1739310630587.png

Dim wb, excel, range As Object

Try

wb = GetWorkbook(Handle, Workbook)
excel = wb.Application
excel.ActiveSheet.OLEObjects.Add(Filename:=PDFFilePath, Link:=False, DisplayAsIcon:=True, IconFileName:=PDFApplicationPath, IconIndex:=0, IconLabel:="Passport.pdf")

Success = True

Catch e As Exception
	Success = False
	Message = e.Message
Finally
	wb = Nothing
	excel = Nothing
	range = Nothing
End Try

3) Your workflow should look something like this:

devneetmohanty07_3-1739310671765.png

4) Pass the proper arguments for the PDF file path which is your actual file path and your adobe application path and it should work as you can see below:

devneetmohanty07_4-1739310739794.png

 

Let me know if you have any further doubts. Thanks for posting your query in the community.

 

---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

RachanaA
Level 3

@devneetmohanty07 Thank you so much. It worked.