views:

317

answers:

1

I am trying to find out how you write VBA to enter a text box into a slide, and enter text. I am also trying to find vba for entering text into the notes section of a PowerPoint slide.

Any help would be greatly appreciated. I have tried to find a site specifically for this, but have not been able to do so

+2  A: 

Entering text into a PPT slide is about the same as entering into the notes section.

You have to start out with a Slide object reference, which represents the slide you're adding to; and you add a text box shape to the slides' shapes collection.

Example:

Sub AddTextBoxToSlide()
    Dim DestSlide As PowerPoint.Slide
    Set DestSlide = ActivePresentation.Slides(1)

    Dim oTextBox As PowerPoint.Shape
    Set oTextBox = DestSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, DestSlide.Parent.PageSetup.SlideHeight, DestSlide.Parent.PageSetup.SlideWidth, DestSlide.Parent.PageSetup.SlideHeight / 12)

    oTextBox.TextFrame.TextRange.Text = "Shape text here"
End Sub

All this does is adds a text box shape to the first slide in the active presentation at the top of the slide. It is as wide as the slide and 1/12th the height of the slide. The parameters for Shapes.AddTextbox() are pretty self-explanatory...

To add to the notes section, I just use the NotesPage object on the slide your notes page is in...so the above code would be about the same, except:

    Set oTextBox = DestSlide.NotesPage.Shapes.AddTextbox(msoTextOrientat...
Jon Fournier
thanks so much. i have been looking for something very quick and to the point for a good while!!how do you work with the text box? change the size, font, underline, etc?thanks again Jon!
Justin
also how would i adjust this code to adjust the size of the text box?
Justin