PDA

View Full Version : Powerpoint underline style



lesaussice
04-16-2012, 03:55 AM
I can't figure out the syntax for the new underline styles in Powerpoint 2007 onwards. I need to set a dotted underline to a TextRange (underline style > dotted line from the Font dialog) but can't find the attribute. I can only work out how to turn on underline and it uses the default solid underline.

Code currently like this..

With rngUnderline
.Font.Underline = msoTrue
End With

You'd think there was a .Font.Underline.Style property but seemingly not. Anyone got any ideas?

John Wilson
04-16-2012, 06:26 AM
To use the new text features you must work with the TextFrame2 object. In 2007 this is a bit broken so you might want to explain how you referenced mgunderline. In 2010 you can use TextRange2.

Sub newstuff()
'This is broken in 2007 but works in 2010!
Dim otx2 As TextRange2
Set otx2 = ActiveWindow.Selection.TextRange2
otx2.Font.UnderlineStyle = msoUnderlineDotDashLine
End Sub

lesaussice
04-16-2012, 06:56 AM
John,

Great, that's solved it..

RngUnderline was set to a specific character range via the TextFrame rather than the TextFrame2 object. Like you say, things are a bit broken in PPT 2007 but I'm now able to use UnderlineStyle to apply my dotted underline.

Cheers

John Wilson
04-17-2012, 01:08 AM
Can you try changing the undeline color with vba and tell me what you see.

lesaussice
05-01-2012, 03:22 AM
Sorry.. Taken me a while to come back to this. I did get around the problem, but I had to do it by referring to the shape's textframe2 (and then the characters within it) rather than setting those characters as a range and then applying the underlinestyle to it. The latter (bizarely) results in PPT not exposing the relevant properties.

Coming from Excel / Access, PPT VBA is quite odd and seems a bit unloved by MS..