Reputation: 83
I've been trying to create a macro that converts all the numbers in a text box, on a slide, to superscript but I'm finding Powerpoint VBA to be very strange.
I've tried this short line of code as a starter, but this doesn't seem to select properly.
ActivePresentation.Slides(1).Select.Font.superscript = True
Any help would be much appreciated.
Thank you!
Upvotes: 0
Views: 433
Reputation: 14809
First off, never select anything unless you absolutely must (rare, very rare). Next, you've selected a Slide object. Slides don't have any font properties, so you can't SET them.
Here's an example that sets all of the characters in the currently selected shape to superscript. You'll likely want to refine it to iterate through all the shapes in the slide, and to skip any characters that aren't numbers. [Edited to Super rather than Sub-script characters and ONLY numeric characters]
Sub SuperscriptMe()
Dim oSh As Shape
Dim x As Long
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh.TextFrame.TextRange
For x = 1 To .Characters.Count
' verify that the character is a number
If IsNumeric(.Characters(x)) then
.Characters(x).Font.Superscript = True
End If
Next
End With
End Sub
Upvotes: 1