Consulting

Results 1 to 5 of 5

Thread: Add Text to different slides

  1. #1

    Add Text to different slides

    Hi,

    I have some code which adds text "NEW" to a specific slide eg. slide 2.

    I would now like to amend code so that this same text ("NEW") is added to two or more slides (eg. slides 1,2 and 3).

    How can I amend code to do this?

    Below code for text added to 1 slide (ie. slide2).

    HTML Code:
    Sub Textboxnew()
        Dim myTextBox As Shape
        With ActivePresentation.Slides(1)
               Set myTextBox = .Shapes.AddTextbox _
                (Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _
                Width:=100, Height:=100)
            myTextBox.TextFrame.TextRange.Text = "NEW"
            myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed
            myTextBox.TextFrame.TextRange.Font.Size = 20
    End With
    End Sub
    Thanks,
    Nic


  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Here are two different ways

    The first adds to 1,2,3 the second only to selected slides

    Sub Textboxnew()
        Dim myTextBox As Shape
        Dim mySld As Long
        On Error Resume Next
        'add to slide 1,2,3 change as required
        For mySld = 1 To 3
        With ActivePresentation.Slides(mySld)
               Set myTextBox = .Shapes.AddTextbox _
                (Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _
                Width:=100, Height:=100)
            myTextBox.TextFrame.TextRange.Text = "NEW"
            myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed
            myTextBox.TextFrame.TextRange.Font.Size = 20
    End With
    Next mySld
    End Sub
    
    
    Sub Textboxnew_Sel()
    
    'adds only to selected slides
        Dim myTextBox As Shape
        Dim osld As Slide
        Dim osldRng As SlideRange
        On Error Resume Next
       Set osldRng = ActiveWindow.Selection.SlideRange
        For Each osld In osldRng
               Set myTextBox = osld.Shapes.AddTextbox _
                (Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _
                Width:=100, Height:=100)
            myTextBox.TextFrame.TextRange.Text = "NEW"
            myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed
            myTextBox.TextFrame.TextRange.Font.Size = 20
    Next osld
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Thanks John,

    So if I wanted to add text to slides 2,4 and 6 where would I put this the code below?

    Sub Textboxnew_Sel() 
         
         'adds only to selected slides
        Dim myTextBox As Shape 
        Dim osld As Slide 
        Dim osldRng As SlideRange 
        On Error Resume Next 
        Set osldRng = ActiveWindow.Selection.SlideRange 
        For Each osld In osldRng 
            Set myTextBox = osld.Shapes.AddTextbox _ 
            (Orientation:=msoTextOrientationHorizontal, Left:=450, Top:=20, _ 
            Width:=100, Height:=100) 
            myTextBox.TextFrame.TextRange.Text = "NEW" 
            myTextBox.TextFrame.TextRange.Font.Color.RGB = vbRed 
            myTextBox.TextFrame.TextRange.Font.Size = 20 
        Next osld 
    End Sub
    Thanks,
    Nic

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Select slides 2,4,6 (hold down CTRL)
    Copy the code

    Open the vba editor ALT f11
    Insert module Paste in the code
    f5 to run OR go back to normal view View > Macro > Run
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    great thanks!

    Nic


Posting Permissions

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