Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Thanked 1 Time in 1 Post

    Excel code to control powerpoint (Office xp)

    I have a powerpoint file with 100 slides. I have codes on the slides indicating the slide number and a period and a sequential number. So slide 12 might have <12.1>, <12.2>, <12.3> ... to <12.15>. Slide 20 might have <15.1>, <15.2> etc.

    My problem is that the slides have been moved around and now i have to renumber all these codes. I would like to have a macro that runs from excel and controls this ppt file. I need all the <##.#> changed to whatever the current slide number is. I don't need anything after the period changed.

    So if slide 12 has been moved and is now slide 15, i need all the <12. changed to <15. These codes are in text boxes. How do i loop through the text boxes on a slide and change the codes? Thanks for the help.

  2. #2
    4 Star Lounger
    Join Date
    Aug 2003
    Stroud, United Kingdom
    Thanked 0 Times in 0 Posts

    Re: Excel code to control powerpoint (Office xp)

    Hi, I take it you mean the slide number in the powerpoint outline view Index? This is the slide Index in the ActivePresentation object.

    The following macro will loop through each slide in the active presentation, and print to the debug window the slide Index and all of the text in that slide. Hope this helps as a starting point.

    I guess you could put in code to check for a string that has "<" and ">" characters in it and providing these are no where else within the slide you could then use this and the SlideIndex property to change that string for the specific textbox that the string is in.

    Sub temp()
    Dim strT As String, shp As Shape, s As Slide

    For Each s In ActivePresentation.Slides ' this goes through each slide in the show

    For Each shp In s.Shapes ' this goes through each shape in that slide

    If shp.HasTextFrame = True Then 'checks for text within the shape
    'concatenate all text from all shapes in that slide - add extra code here etc
    If shp.TextFrame.HasText = True Then strT = strT & " _ " & shp.TextFrame.TextRange.Text
    End If

    Next shp

    'print out slide Index and text from that slide for each slide to the debug window
    Debug.Print s.SlideIndex
    Debug.Print strT

    Next s
    End Sub

    To run this from Excel you can either add the Powerpoint Library as a reference in the VBE, or you would have to define the variables for Active Presentation, Slides, shapes etc as objects and set them. I personally would run it from within Powerpoint first to make sure it works.


Posting Permissions

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