I’m trying to change all the PowerPoints in a folder that contains multiple layers of subfolders from .ppt to .pptx
I have seen another thread where a user gave a package that can do so, but our company does not have access to go! Packages, so I can’t use that
Can anyone help?
-
Assign Activity:
allFiles = Directory.GetFiles("C:\YourFolder", "*.ppt", SearchOption.AllDirectories) -
For Each file In allFiles
-
Invoke Code Activity (with
Inargument:fileas String,Outargument:convertedPathas String):Dim pptApp = New Microsoft.Office.Interop.PowerPoint.Application() Dim presentation = pptApp.Presentations.Open(file, WithWindow:=Microsoft.Office.Core.MsoTriState.msoFalse) convertedPath = System.IO.Path.ChangeExtension(file, ".pptx") presentation.SaveAs(convertedPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation) presentation.Close() pptApp.Quit() -
(Optional) Delete old file:
File.Delete(file)
Note: Import namespaces:
System.IOMicrosoft.Office.Interop.PowerPointMicrosoft.Office.Core
PowerPoint must be installed.
It shows “Invoke code: Exception has been thrown by the target of an invocation” when I run the flow
Can you please run in debug and open the locals panel and exception detaila from there please..that would show the exact exception message
Also currentfile to be linked to in argument of invoke code
Cheers
Assign the argument correctly also check the direction and for better understanding please share the screenshot
Hello @bamboojoanne
Making it happen “behind the scenes” without GUI interaction is deffinently the best way to go.
However if you experience problems with that approach, you could still make the procedure from using UI activities.
Regards
Soren
- Go to Manage packages and download UiPath.Presentation.Activities. I believe the company have access to official packages of UiPath
- Use activity - For each file in folder with below mentioned properties
- Using power point scope and save as option - you can convert all the ppt files to pptx format.
- Include delete current file if you don’t want to keep ppt file
Hi, I checked the arguments, and they are all corresponding to how you wrote them above, and I also tried added the Currentfile as in, which still didn’t work
I’m sorry, but I can’t upload screenshots, our company disabled such action
It said RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —-> RemoteException wrapping System.Runtime.InteropServices.COMException: Presentations (unknown member): Invalid request. filename cannot exceed 255 characters.
Can you give me the error message
When ran, it shows:
Invoke code: Exception has been thrown by the target of an invocation
And in exception detail:
RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —-> RemoteException wrapping System.Runtime.InteropServices.COMException: Presentations (unknown member): Invalid request. filename cannot exceed 255 characters.
The error means one or more .ppt files have file paths longer than 255 characters, which PowerPoint cannot open.
Solution: Skip files with long path
Before opening the file in Invoke Code, add this check in your For Each:
If file.Length <= 255 Then
' Call Invoke Code
End If
Or in Invoke Code, wrap with condition:
If file.Length <= 255 Then
Dim pptApp = New Microsoft.Office.Interop.PowerPoint.Application()
Dim presentation = pptApp.Presentations.Open(file, WithWindow:=Microsoft.Office.Core.MsoTriState.msoFalse)
convertedPath = System.IO.Path.ChangeExtension(file, ".pptx")
presentation.SaveAs(convertedPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation)
presentation.Close()
pptApp.Quit()
Else
convertedPath = "" ' Skip file
End If
This way, it skips files with too long paths instead of crashing.
But then wouldn’t it mean some of my files will be skipped and can’t change from ppt to pptx?
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.

