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

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

Formatting the Bullets for a Text Range

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

Formatting the Text in a Text Range

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

Returning and Setting the Text in a Text Range

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

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

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

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

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

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

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

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

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

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

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