Consulting

Results 1 to 3 of 3

Thread: Formatting dynamically added Textboxes

  1. #1
    VBAX Newbie
    Joined
    Dec 2005
    Posts
    2
    Location

    Formatting dynamically added Textboxes

    I am adding textboxes to a slide by using AddTextBox method.

    Now i want to format these textboxes according to the chosen template (which may vary according to user's selection).

    Currently the textboxes contain some default styles. but i want to be the same as defined in the SlideMaster. for example, if the MasterSlide's body text is Arial 12 Bold, then i want the dynamically added textbox to be following the same conventions....

    Any ideas ??

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi badbee and welcome to VBAX

    Here's some code that shows the basic method - as you can see, by referring to the placeholder object on the slidemaster, you can get its properties and use them to set up the new textbox.
    Sub AddCustomTextbox()
    Dim objTextBox As Shape
    Dim objMasterTextBox As Shape
    Dim shp As Shape
    'get a reference to the body text placeholder on the slide master
        For Each shp In ActivePresentation.SlideMaster.Shapes.Placeholders
            If shp.PlaceholderFormat.Type = ppPlaceholderBody Then
                Set objMasterTextBox = shp
                Exit For
            End If
        Next
    If objMasterTextBox Is Nothing Then
            MsgBox "No body textbox found on slidemaster"
        Else
            'add textbox with size
            Set objTextBox = ActiveWindow.Selection.SlideRange.Shapes.AddTextbox( _
                msoTextOrientationHorizontal, 50, 50, 400, 24)
            With objTextBox.TextFrame
                .AutoSize = ppAutoSizeShapeToFitText
                .TextRange.Text = "[Enter Text]"
                .TextRange.ParagraphFormat.Bullet.Visible = msoFalse
            End With
            'match format with that of objMasterTextBox
            'use the first paragraph, in case there is a mixture in the placeholder
            With objTextBox.TextFrame.TextRange.Font
                .Name = objMasterTextBox.TextFrame.TextRange.Paragraphs(1).Font.Name
                .Size = objMasterTextBox.TextFrame.TextRange.Paragraphs(1).Font.Size
                .Bold = objMasterTextBox.TextFrame.TextRange.Paragraphs(1).Font.Bold
                .Italic = objMasterTextBox.TextFrame.TextRange.Paragraphs(1).Font.Italic
            End With
            'set more properties as required...
    End If
        objTextBox.TextFrame.TextRange.Characters.Select
    End Sub
    There are a lot of approaches to building this into custom functionality. If you frequently want to add pre-defined shapes (dynamic or otherwise), it might be better to create a class module and use the code it's Initialize event - then each time you want a new shape, just create an instance of that class.
    K :-)

  3. #3
    VBAX Newbie
    Joined
    Dec 2005
    Posts
    2
    Location
    Thanks,
    The problem is solved!!
    Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •