1

I have VBA code running from excel which produces a 6 slide powerpoint presentation using copied in charts from an excel document. What code lines would I use to insert a title slide, and define the text on that slide (title + sub title)? Using Excel 2007.

4 Answers 4

6

So, some additional alternative for @Siddharth Rout proposal (which is good as well). I use .AddTitle method which could be beneficial in case of formatting of that shape.

Sub add_title()

Dim shpCurrShape As Shape

Dim ppPres As Presentation

Set ppPres = ActivePresentation
With ppPres.Slides(1)

If Not .Shapes.HasTitle Then
    Set shpCurrShape = .Shapes.AddTitle
Else
    Set shpCurrShape = .Shapes.Title
End If

    With shpCurrShape
    With .TextFrame.TextRange
        '~~> Set text here
        .Text = "BLAH BLAH"
        '~~> Alignment
        .ParagraphFormat.Alignment = 3
       '~~> Working with font
       With .Font
          .Bold = msoTrue
          .Name = "Tahoma"
          .Size = 24
          .Color = RGB(0, 0, 0)
       End With
    End With
End With
End With
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

+ 1 for the alternative :)
2

You have to use the .AddTextbox to add the Title

See this example

Dim shpCurrShape As Object

'~~> If doing from within PP remove oPPApp else it is your PP object
With oPPApp.ActivePresentation.Slides(1)
    '~~> Add Heading
    'expression.AddTextbox(Orientation, Left, Top, Width, Height)
    Set shpCurrShape = .Shapes.AddTextbox(1, 18, 48, 654, 29.08126)

    With shpCurrShape
        With .TextFrame.TextRange
            '~~> Set text here
            .Text = "BLAH BLAH"
            '~~> Alignment
            .ParagraphFormat.Alignment = 3
           '~~> Working with font
           With .Font
              .Bold = msoTrue
              .Name = "Tahoma"
              .Size = 24
              .Color = RGB(0, 0, 0)
           End With
        End With
    End With
End With

Screenshot

enter image description here

2 Comments

One suggestion, as the intention is to add title you could use .Shapes.AddTitle instead of .Shapes.AddTextbox which could be beneficial in some situation...
True. You can use .AddTitle as well to restore a previously deleted title placeholder in the slide.:)
1

Here's another solution which uses the "Add" method, and uses Powerpoint's slideLayout for a Title slide.

Sub AddTitleSlide()
Dim sld As Slide
Dim ttlBox As Shape

Set sld = ActivePresentation.Slides.Add(1, ppLayoutTitle)
Set ttlBox = sld.Shapes("Title 1")

ttlBox.TextFrame2.TextRange.Characters.Text = "Here is the slide title!"

End Sub

Comments

0

Heres a solution I use:

'Setup PPTX File
Set oPA = CreateObject("PowerPoint.Application")
oPA.Visible = True
Set oPP = oPA.ActivePresentation
slideNumber = oPP.Slides.Count + 1
Set oPS = oPP.Slides.Add(slideNumber, ppLayoutBlank)
oPA.ActiveWindow.View.GotoSlide (slideNumber) 'this line makes testing easier otherwise not required
Set sObj = oPP.Slides(slideNumber)
sObj.Shapes(1).TextFrame.TextRange.Text = titleText

 'Include Text in Powerpoint
oPP.Slides(slideNumber).CustomLayout = oPP.Designs(1).SlideMaster.CustomLayouts(X) 'X=Layout Number with a title page
sObj.Shapes(1).TextFrame.TextRange.Text = titleText

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.