Setting and adding a Title box in slide script

doverfelt

New Member
Joined
Oct 27, 2016
Messages
10
I have a script someone gave me to autogenerate a PowerPoint slide from within a workbook. However, I need to add a title box and value into the script and not a VBA guy at all. The script is below...can anyone help me out with the code to create the title box and populate it? I can modify the code to set the text I need, but need the base syntax....

Any help out there?

D

Sub ExcelRangeToPowerPoint()




Dim rng As Range
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object


'Copy Range from Excel
Set rng = ThisWorkbook.ActiveSheet.Range("A1:O86")


'Create an Instance of PowerPoint
On Error Resume Next

'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")

'Clear the error between errors
Err.Clear


'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")

'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If


On Error GoTo 0


'Optimize Code
Application.ScreenUpdating = False

'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add


'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 12) '11 = ppLayoutTitleOnly


'Copy Excel Range
rng.Copy


'Paste to PowerPoint and position
mySlide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)

'Set position:
myShape.Left = 50
'it was at 66
myShape.Top = 100
'it was at 152
myShape.Width = 75
myShape.Height = 175
'Clear The Clipboard
Application.CutCopyMode = False

'Make PowerPoint Visible and Active
PowerPointApp.Visible = True
PowerPointApp.Activate





End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try...

Code:
'
'
'

'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly

'Add title to the slide
mySlide.Shapes(1).TextFrame.TextRange.Text = "MyTitle"

'
'
'

Hope this helps!
 
Last edited:
Upvote 0
Try...

Code:
'
'
'

'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly

'Add title to the slide
mySlide.Shapes(1).TextFrame.TextRange.Text = "MyTitle"

'
'
'

Hope this helps!
Is there a few lines of code I could add to this so that the background color and font color of the textbox may be changed?
 
Upvote 0
Is there a few lines of code I could add to this so that the background color and font color of the textbox may be changed?

First, add the following declaration at the beginning of the code...

VBA Code:
Dim myTitlePlaceHolder As Object

Then try...

VBA Code:
'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly

'Get the title placeholder
Set myTitlePlaceHolder = mySlide.Shapes.Placeholders(1)

'Add title and format placeholder
With myTitlePlaceHolder
    .Fill.BackColor.RGB = RGB(0, 0, 255) 'blue (change as desired)
    With .TextFrame.TextRange
        .Font.Color.RGB = RGB(255, 255, 255) 'white (change as desired)
        .Text = "MyTitle"
    End With
End With

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top