PowerPoint COM Interop

Hello UiPath Gurus,

I am trying to transfer a matrix of data points into a PowerPoint visual (retaining formatting), and I have VBA defined and working.

When transferring to invoke code activity in UiPath, I make sure
(1) to include “Dim ppt_App As Microsoft.Office.Interop.PowerPoint.Application, ppt_Pres As Microsoft.Office.Interop.PowerPoint.Presentation, ppt_Slide As Microsoft.Office.Interop.PowerPoint.Slide” at the top of the script
(2) import “Microsoft.Office.Interop.Excel” and “Microsoft.Office.Interop.PowerPoint.” I also installed the following 2 packages:
image

(3) I edited the .xaml code in notepad to include the assembly references for Excel and PowerPoint, as shown in HOWTO: Use MS Office COM interop with UiPath

When I run the code however, I am still receiving the following error, which is saying I still need an assembly reference:
Run everything: No compiled code to run
error BC30652: Reference required to assembly ‘office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ containing the type ‘Microsoft.Office.Core.MsoTriState’. Add one to your project. At line 62
error BC30652: Reference required to assembly ‘office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ containing the type ‘Microsoft.Office.Core.MsoTriState’. Add one to your project. At line 66

image

Any thoughts on how to fix this? I’ve read some things about “dll” and importing .PowerPoint.Presentations, but any attempts I’ve made to do those things make no difference.

Thank you!

1 Like

@Shelby_Pons How many total lines of code are present? Can you show a Screenshot of the Code? If possible share the xaml file. You might need to use the full namespace sometimes.

2 Likes

Can you show the whole code? @Shelby_Pons

2 Likes

@supermanPunch and @Manish540 Thank you for responding so quickly. Please see full VB.NET below. The only other activities in this particular .xaml are assign activities for local folders (which are definitely correct).

Dim arr_Metrics(0 To 3, 0 To 3) As String 'Define array of public variables
Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb_InputReport As Microsoft.Office.Interop.Excel.Workbook
Dim ws_Metrics As Microsoft.Office.Interop.Excel.Worksheet 'Dim excel stuff
Dim I As Integer, J As Integer
Dim ppt_App As Microsoft.Office.Interop.PowerPoint.Application, ppt_Pres As Microsoft.Office.Interop.PowerPoint.Presentation, ppt_Slide As Microsoft.Office.Interop.PowerPoint.Slide 'Dim ppt stuff
Dim filepath_PPT As String, filename_PPT As String
Dim wkb As Microsoft.Office.Interop.Excel.Workbook
Dim AlreadyOpen_Excel As Boolean
Dim ppt As Microsoft.Office.Interop.PowerPoint.Presentation
Dim AlreadyOpen_PPT As Boolean

'Check Excel Open
On Error Resume Next
wkb = excel.Workbooks(strInputReport)
AlreadyOpen_Excel = Not wkb Is Nothing
wkb = Nothing

'Check PPT Open
On Error Resume Next
ppt = ppt_App.Presentations(strSlide)
AlreadyOpen_PPT = Not ppt Is Nothing
ppt = Nothing

'Check if wb is already open then Set Excel references
If AlreadyOpen_Excel Then
wb_InputReport = excel.Workbooks(strInputReport)
Else
wb_InputReport = excel.Workbooks.Open(Filename:=strInputReport)
End If

ws_Metrics = CType(wb_InputReport.Worksheets(“Metrics”),Microsoft.Office.Interop.Excel.Worksheet)

'1st Column
arr_Metrics(0, 0) = Math.Round((CDbl(ws_Metrics.Range(“D5”).Value) * 100), 2) & “%”
arr_Metrics(1, 0) = Math.Round((CDbl(ws_Metrics.Range(“D6”).Value) * 100), 2) & “%”
arr_Metrics(2, 0) = Math.Round((CDbl(ws_Metrics.Range(“D7”).Value) * 100), 2) & “%”
arr_Metrics(3, 0) = Math.Round((CDbl(ws_Metrics.Range(“D9”).Value) * 100), 2) & “%”

'2nd Column
arr_Metrics(0, 1) = CStr(ws_Metrics.Range(“E5”))
arr_Metrics(1, 1) = CStr(ws_Metrics.Range(“E6”))
arr_Metrics(2, 1) = CStr(ws_Metrics.Range(“E7”))
arr_Metrics(3, 1) = CStr(ws_Metrics.Range(“E8”))

'3rd Column
arr_Metrics(0, 2) = CStr(ws_Metrics.Range(“F5”))
arr_Metrics(1, 2) = CStr(ws_Metrics.Range(“F6”))
arr_Metrics(2, 2) = CStr(ws_Metrics.Range(“F7”))
arr_Metrics(3, 2) = CStr(ws_Metrics.Range(“F8”))

'4th Column
arr_Metrics(0, 3) = CStr(ws_Metrics.Range(“G5”))
arr_Metrics(1, 3) = CStr(ws_Metrics.Range(“G6”))
arr_Metrics(2, 3) = CStr(ws_Metrics.Range(“G7”))
arr_Metrics(3, 3) = CStr(ws_Metrics.Range(“G8”))

'Check if open and Reference presentation
If AlreadyOpen_PPT Then
ppt_Pres = ppt_App.Presentations(filename_PPT)
Else
ppt_Pres = ppt_App.Presentations.Open(filepath_PPT & filename_PPT)
End If

'Save as new document
ppt_Pres.SaveAs (filepath_PPT & “TEST PPT OUTPUT”)

'Define slide
ppt_Slide = ppt_Pres.Slides(1)

For I = 1 To 4
For J = 1 To 4
ppt_Slide.Shapes(“shp_” & I & “-” & J).TextEffect.Text = arr_Metrics(I, J)
Next J
Next I

'Save/Close Presentation and Kill ppt application
'With ppt_Pres
’ .Save
’ .Close
'End With
ppt_Pres.Save
ppt_Pres.Close

ppt_App.Quit

Hi Shelby,

I see. In order to solve this problem you have to options:
(1) Install package for MicrosoftOfficeCore (together with Interops PowerPoint)


(2) Install package for All Microsofts interops (for some reason this solves the issue as well):

I think there are other Core Packages that may work but I haven’t tested them. Take into consideration that this are not official packages. They are maintained by individuals, so check with your company’s policy. (also, I didn’t test your code. I did the troubleshooting with a super simple example and I manage to recreate and solve the error, so I hope it works for you)

Unfortunately these have not fixed the error. Still receiving generic message “Exception has been thrown by the target of an invocation.”

Have you had experience with errors due to having TOO MANY packages/imported namespaces, etc? I’ve read in other cases that actually removing some packages helped, but I’m not sure which ones to target for removal…

Hi Shelby,

If you check the error into detail, is it saying that Object reference not set to an instance of an object? (you have to look inside the error message). When you have an error with Invoke code (other than assemblies and all that other stuff), you can check the real origin of the problem at the end of the log message:

This could be because you have to initialize the Powerpoint app–>
Dim ppt_app As Microsoft.Office.Interop.PowerPoint.Application = New Microsoft.Office.Interop.PowerPoint.Application

And you have to do the same with Excel application. I recomend that you test your code step by step.

Let me know if it works for you.

2 Likes

Yes I have that error when i look in the details, I see now.

However, in the = New Microsoft.Office.Interop.PowerPoint.Application piece you mention, “Application” is not an option–only “ApplicationClass”

If I try “= New Microsoft.Office.Interop.PowerPoint._Application” instead, the following error appears

image

Excellent!! @RockSolid That “= New Microsoft.Office.Interop.PowerPoint.Application()” is what was missing. I didn’t realize we needed to add the “()” to the end. It’s working now. Thank you!!

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.