Hi. I’m new to UiPath and this is my first time posting. I’m working on a Powerpoint automation. I’m reading an Excel file with multiple sheets. The number of sheets is variable, based on the customer’s data. I check for the existence of a sheet, and if it exists, I use the data to replace text on applicable Powerpoint slides. If a sheet doesn’t exist, I need to delete the related slides. I can’t use slide numbers to delete, because the numbers change after I delete slides. I want to be able to delete based on a text value on the slide. Is that possible? I hope that makes sense. I’d appreciate assistance with this. Thank you!
Hi @lbowen
I just tried a LLM code and it works, Use invoke code
Dim pptApp As Microsoft.Office.Interop.PowerPoint.Application = New Microsoft.Office.Interop.PowerPoint.Application()
Dim pptPresentation As Microsoft.Office.Interop.PowerPoint.Presentation = pptApp.Presentations.Open("Give Full file path", WithWindow:=MsoTriState.msoFalse)
Dim slideDeleted As Boolean = False
Try
' Loop through all slides in the presentation
For i As Integer = pptPresentation.Slides.Count To 1 Step -1
Dim slide As Microsoft.Office.Interop.PowerPoint.Slide = pptPresentation.Slides(i)
' Search for the text in the slide
Dim containsText As Boolean = False
For Each shape As Microsoft.Office.Interop.PowerPoint.Shape In slide.Shapes
If shape.HasTextFrame = MsoTriState.msoTrue AndAlso
shape.TextFrame.HasText = MsoTriState.msoTrue AndAlso
shape.TextFrame.TextRange.Text.Contains("Text to delete") Then
containsText = True
Exit For
End If
Next
' Delete the slide if the text is found
If containsText Then
slide.Delete()
slideDeleted = True
End If
Next
' Save and close the presentation
pptPresentation.Save()
pptPresentation.Close()
Catch ex As Exception
Throw New Exception("Error while deleting slide: " & ex.Message)
Finally
pptApp.Quit()
End Try
Please import the below namespaces
Microsoft.Office.Interop.PowerPoint
Microsoft.Office.Core
Hope this helps!
Welcome to the community
You can delete using number as well…but do it upside down…that is delete the last slides first and come to first so that the numbers dont change
Or if you want to delete from top only then after every deletion just add a counter number and remove that number from page number you would get the next slide to be deleted
Cheers
Thank you! Thank you! This is amazing! It took me a while to get the namespace importing sorted, but now it’s working great! (I had to make some entries in my xaml file.) This is exactly what I needed! I really appreciate you taking the time to post this solution.
All the best!
Lisa B.
@Anil_G
That would probably work too. A case of me not seeing the forest for the trees.
Thank you!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.