How to automate deletion of all text with Strikethrough formatting in a PowerPoint presentation?

Question:

How can I automate the deletion of all text with Strikethrough formatting in a PowerPoint presentation?

I found this useful link to do it in Excel: https://www.extendoffice.com/documents/excel/4831-excel-remove-delete-strikethrough-text.html

I think something similar can probably be done for PowerPoint, but I have zero experience in VBA and automating Office stuff.

More specifically, I want to do this for all text in all tables in the presentation.

Note: the text inside each cell might have parts of it with Strikethrough and parts that don’t.

What I want to do in the end is parse the tables in the PPT with Python. I was using python-pptx, but it doesn’t have a way of distinguishing if text has Strikethrough formatting. An alternative could be to find a Python library that can detect Strikethrough formatting in the PPT text to be able to filter it out.

Another alternative can be, since I already have a way of doing this in Excel, to automate a way to export the PowerPoint tables into Excel (preserving the formatting so that I can apply the Strikethrough deletion script there).

The slides have tables like this one. This is what I mean by a table.

enter image description here

To give a bit more details about how those tables are stored in the presentation, this is the code I have in python-pptx to get to one of the tables:

import pptx

def parse_pptx(file_name):
    prs = pptx.Presentation(file_name)
    slides = prs.slides
    for i, slide in enumerate(slides):
        if i == 66:
            shapes = slide.shapes
            for shape in shapes:
                if type(shape) == pptx.shapes.graphfrm.GraphicFrame and shape.has_table:
                    table = shape.table
                    if "Test_Table_1" in table.cell(0, 0).text:
                        for j in range(len(table.rows)):
                            for i in range(len(table.columns)):
                                print(table.cell(j, i).text, end=", ")
                            print("")


if __name__ == "__main__":
    pptx_name = Path("test.pptx")
    parse_pptx(pptx_name)
Asked By: tgonzalez89

||

Answers:

If the ‘tables’ in discussion really are PowerPoint (inserted) tables, please, try using the next code:

Sub testIterateShapesType()
     Dim sl As Slide, sh As Shape, tbl As Table, i As Long, j As Long, k As Long
     
     For Each sl In ActivePresentation.Slides
        For Each sh In sl.Shapes
            If sh.Type = msoTable Then
                Set tbl = sh.Table
                For i = 1 To tbl.Rows.Count
                    For j = 1 To tbl.Columns.Count
                        For k = tbl.Cell(i, j).Shape.TextFrame2.TextRange.Characters.Count To 1 Step -1
                            If tbl.Cell(i, j).Shape.TextFrame2.TextRange.Characters(k, 1).Font.Strikethrough Then
                                tbl.Cell(i, j).Shape.TextFrame2.TextRange.Characters(k, 1) = ""
                            End If
                        Next k
                    Next j
                Next i
            End If
        Next
     Next
End Sub

Please, send some feedback after testing it.

Answered By: FaneDuru