VBA/Excel/Access/Word/PowerPoint/Slide Text

Материал из VB Эксперт
Перейти к: навигация, поиск

Check whether the text frame contains text. To do so, check that the HasText property of the TextFrame object is msoTrue

   <source lang="vb">

Sub shape()

   With ActivePresentation.Slides(1).Shapes(1).TextFrame
       If .HasText = msoTrue Then MsgBox .TextRange.Text
   End With

End Sub

</source>
   
  


Formatting the Bullets for a Text Range

   <source lang="vb">

Sub bullet()

   With ActiveSlide.Shapes(1).TextFrame.TextRange.ParagraphFormat.bullet
       .Type = ppBulletUnnumbered
       .Character = 254
       With .Font
           .Name = "Wingdings"
           .Size = 44
           .Color = RGB(255, 255, 255)
       End With
   End With

End Sub

</source>
   
  


Formatting the Text in a Text Range

   <source lang="vb">

Sub format()

   With ActiveSlide.Shapes(2).TextFrame.TextRange.ParagraphFormat
       .Alignment = ppAlignLeft
       .LineRuleAfter = msoFalse
       .SpaceAfter = 18
       .LineRuleBefore = msoFalse
       .SpaceBefore = 18
       .LineRuleWithin = msoFalse
       .SpaceWithin = 12
   End With

End Sub

</source>
   
  


Returning and Setting the Text in a Text Range

   <source lang="vb">

Sub set()

   ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text _
       = "Strategic Planning Meeting"

End Sub

</source>
   
  


Returns the second through fifth words from the first shape on the first slide in the active presentation:

   <source lang="vb">

Sub text()

   MsgBox ActivePresentation.Slides(1).Shapes(1).TextFrame _
       .TextRange.Words(Start:=2, Length:=4)

End Sub

</source>
   
  


Set the text of the second paragraph in the second shape on the sixth slide in the presentation

   <source lang="vb">

Sub textRange()

   ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange _
       .Paragraphs(Start:=2, Length:=1).Text = "VP of Business Development"

End Sub

</source>
   
  


To use a picture as a bullet, set the Type property of the BulletFormat object to ppBulletPicture and then use the Picture method with the Picture argument

   <source lang="vb">

Sub picture()

   With ActiveSlide.Shapes(1).TextFrame.TextRange.ParagraphFormat.Bullet
       .Type = ppBulletPicture
       .Picture Picture:="z:\1.jpg"
   End With

End Sub

</source>
   
  


Use the AddTextbox Method to add a text box to the eighth slide and assign text to it

   <source lang="vb">

Sub textBox()

   Dim myTextBox As Shape
   With ActivePresentation.Slides(1)
       Set myTextBox = .Shapes.AddTextbox _
           (Orientation:=msoTextOrientationHorizontal, Left:=100, Top:=50, _
           Width:=400, Height:=100)
       myTextBox.TextFrame.TextRange.Text = "Corrective Lenses"
   End With

End Sub

</source>
   
  


Use the AddTextEffect to add a WordArt. The WordArt item uses 54-point bold ITC Avant Garde Gothic.

   <source lang="vb">

Sub add()

   Dim QASlide As slide
   With ActivePresentation
       Set QASlide = .Slides.add(Index:=.Slides.Count + 1, Layout:=ppLayoutBlank)
       QASlide.Shapes.AddTextEffect PresetTextEffect:=msoTextEffect28, _
           Text:="Questions " + Chr$(CharCode:=13) + "Answers", _
           FontName:="Garde Gothic", FontSize:=54, FontBold:=msoTrue, _
           FontItalic:=msoFalse, Left:=230, Top:=125
   End With

End Sub

</source>