PDA

View Full Version : [SOLVED:] Strikethrough in PowerPoint vba



crossharu
10-19-2017, 01:17 AM
Hi,

I'm new to this community so I hope I have adhered to all of the rules with this post.

I am trying to create a very crude 'tracked changes' add-in for PowerPoint. The macro would have a keyboard shortcut and button assigned to each of the following functions:

1.) Format selected text as red and strikethrough
2.) Format selected text as black and remove strikethrough
3.) Search document for all text which is red with strikethrough as well as all text which is red only and delete/format as black respectively allowing the user to ignore instances on a case by case basis.

The only problem is that the Font.StrikeThrough property of a TextRange does not appear to be accessible in PowerPoint vba. I have submitted feedback to Microsoft on this but I am hoping someone might be able to suggest a clever way (perhaps utilising excel's Font.StrikeThrough property) to achieve the above attempting to minimise any performance hit of opening another application.

Thanks in advance!

Paul_Hossler
10-19-2017, 06:01 AM
Try this -- uses .TextRange2, not .TextRange





Sub ST()
With ActiveWindow.Selection
.TextRange2.Font.Strikethrough = msoTrue
.TextRange2.Font.Fill.ForeColor.RGB = vbRed
End With
End Sub



For ref: http://vba.relief.jp/powerpoint-vba-textrange-textrange2-properties-methods-list/

crossharu
10-19-2017, 06:46 AM
Exactly what I was looking for. Many thanks, Paul!

crossharu
10-22-2017, 08:10 AM
Paul - I wonder if you might be able to help me further with the below please?

I'm trying to use the below to search for all instances of strikethrough formatted text in a presentation:


For each sld in Application.ActivePresentation.Slides
For each shp in sld.Shapes
If shp.HasTextFrame then
Set txtrng = shp.TextFrame.TextRange2

But apparently TextFrame doesn't support TextRange2 and TextRange doesn't have the strikethrough property that I need.

Any ideas?

Thanks again.

Paul_Hossler
10-24-2017, 06:20 AM
Sorry - that's too advanced for me -- I only know the very basics of PP VBA

crossharu
10-25-2017, 10:44 AM
No worries Paul. Has anyone else come across this problem?

Thanks.

John Wilson
10-26-2017, 06:15 AM
You need to use shp.TextFrame2.Textrange

crossharu
10-27-2017, 09:43 AM
Perfect, thanks John.