Powerful PowerPoint for Educators: Using Visual Basic for Applications to Make PowerPoint Interactive


Manipulating Parts of Text in an Ob ject


Download 1.37 Mb.
Pdf ko'rish
bet79/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   75   76   77   78   79   80   81   82   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

Manipulating Parts of Text in an Ob ject
TextRange
is an interesting crea ture. The 
TextRange
of a shape re fers to
the entire text in that shape, but any thing you can do to a 
TextRange
, you can
do to a part of a
TextRange
. You can do things to spe cific paragraphs within the 
TextRange
, spe cific words within the 
TextRange
, and spe cific characters
within the 
TextRange
.
For ex ample, if you wanted to change to blue the color of the text in the en -
tire third shape of the current slide, you could use the fol lowing code:
ActivePresentation.SlideShowWindow.View.Slide.Shapes(3). _
TextFrame.TextRange.Font.Color.RGB = vbBlue
82 A Scripting Bag of Tricks


Almost iden tical code can be used to change the second para graph of the third
shape on the current slide to blue:
ActivePresentation.SlideShowWindow.View.Slide.Shapes(3). _
TextFrame.TextRange.Paragraphs(2).Font.Color.RGB = vbBlue
Note that paragraphs in clude the New Paragraph symbol,
Chr$(13)
, as part of
the paragraph. Thus, you must be careful when chang ing the text of a paragraph
to be sure that each paragraph ends with
Chr$(13)
. See the Mys tery Example
later in this chap ter for an example of this. With an other small change, the sec-
ond word becomes blue:
ActivePresentation.SlideShowWindow.View.Slide.Shapes(3). _
TextFrame.TextRange.Words(2).Font.Color.RGB = vbBlue
Note that VBA counts punctuation marks as words. For example, the text
“Hello, my name is David” has six words (by VBA’s count; who said computers
were smart?), with the comma be ing the second word. With an other small
change, the second char ac ter be comes blue:

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   75   76   77   78   79   80   81   82   ...   191




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling