VBA in PPT from XL

vbaNewby

Board Regular
Joined
Jan 26, 2011
Messages
138
Hi,

I know this is an excel forum but there are many VBA experts here. I am using an vba sub from excel to create a powerpoint slide.

I need to know how to add slide numbers in my powerpoint slides. This is done manually in 2007 by insert tab > slide number > check off slide number in dialog box > click ok.

Since PPT 2007 does not allow you to record macros, I cannot use to see how it is done in VBA.

I have tried this but no success:

Code:
With PP.Slides.Range.HeadersFooters
        .SlideNumber.Visible = msoTrue
    End With

Where PP is defined as
Code:
Dim PP as PowerPoint.Presentation

Any of you guru's know how to accomplish this? Or maybe perhaps anyone have an old version of PPT (where they still allow you to record macros) and can record this and paste the results into this thread?

Thanks a bunch.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Do you want this to run from within PowerPoint or from Excel? 97 to PowerPoint 2003 will allow you to record a macro so let me know where it is to be run from.
 
Upvote 0
Do you want this to run from within PowerPoint or from Excel? 97 to PowerPoint 2003 will allow you to record a macro so let me know where it is to be run from.

Directly from PowerPoint would be great. I am coding in XLS but I've added my PPT reference so I can make PPT calls directly in XLS.

Thank you Trevor.
 
Upvote 0
Hi,

I know this is an excel forum but there are many VBA experts here. I am using an vba sub from excel to create a powerpoint slide.

I need to know how to add slide numbers in my powerpoint slides. This is done manually in 2007 by insert tab > slide number > check off slide number in dialog box > click ok.

Since PPT 2007 does not allow you to record macros, I cannot use to see how it is done in VBA.

I have tried this but no success:

Code:
With PP.Slides.Range.HeadersFooters
        .SlideNumber.Visible = msoTrue
    End With

Where PP is defined as
Code:
Dim PP as PowerPoint.Presentation

Any of you guru's know how to accomplish this? Or maybe perhaps anyone have an old version of PPT (where they still allow you to record macros) and can record this and paste the results into this thread?

Thanks a bunch.

Here is the recorded code

Sub mcrSlideNumbers()
'
' Macro recorded 10/03/2011 by Trevor Glover
'
If ActivePresentation.HasTitleMaster Then
With ActivePresentation.TitleMaster.HeadersFooters
With .DateAndTime
.Format = ppDateTimeMdyy
.Text = ""
.UseFormat = msoTrue
.Visible = msoFalse
End With
.Footer.Visible = msoFalse
.SlideNumber.Visible = msoTrue
End With
End If
With ActivePresentation.SlideMaster.HeadersFooters
With .DateAndTime
.Format = ppDateTimeMdyy
.Text = ""
.UseFormat = msoTrue
.Visible = msoFalse
End With
.Footer.Visible = msoFalse
.SlideNumber.Visible = msoTrue
End With
With ActivePresentation.Slides.Range.HeadersFooters
With .DateAndTime
.Format = ppDateTimeMdyy
.Text = ""
.UseFormat = msoTrue
.Visible = msoFalse
End With
.Footer.Visible = msoFalse
.SlideNumber.Visible = msoTrue
End With
End Sub
 
Upvote 0
Thanks Trevor, I'll try to form this to what I need and let you know if I come up with something.

Appreciate it.
 
Upvote 0
I use this code to create a presentation from Excel perhaps this can help to?

Code:
Dim pptApp As PowerPoint.Application
Dim pres1 As PowerPoint.Presentation
Dim Slide1 As PowerPoint.Slide
Set pptApp = CreateObject("PowerPoint.Application")
With pptApp
      .Visible = True
      Set pres1 = pptApp.Presentations.Add
End With
Set Slide1 = pres1.Slides.Add(1, ppLayoutText)

End Sub
 
Upvote 0
I use this code to create a presentation from Excel perhaps this can help to?

Code:
Dim pptApp As PowerPoint.Application
Dim pres1 As PowerPoint.Presentation
Dim Slide1 As PowerPoint.Slide
Set pptApp = CreateObject("PowerPoint.Application")
With pptApp
      .Visible = True
      Set pres1 = pptApp.Presentations.Add
End With
Set Slide1 = pres1.Slides.Add(1, ppLayoutText)

End Sub
Thanks Trevor. Yes, I already am adding slides via VBA.

My problem is getting the slide numbering to work. Do you have three slides when you recorded that macro? I'm wondering why the same set of code repeats three times...

Thanks again.
 
Upvote 0
When I recorded I used a current slide show that had loads of slides. I have since looked at redeveloping and have come up with this. I have ensured the references are set for PowerPoint and tested it several times, seems to work OK, I have included some text in the footer options, I have highlighted that in Red, I hope it helps.

Code:
Sub ppT()
Dim pptApp As PowerPoint.Application
Dim pres1 As PowerPoint.Presentation
Dim Slide1 As PowerPoint.Slide
Dim s As PowerPoint.Slide
Set pptApp = CreateObject("PowerPoint.Application")
With pptApp
      .Visible = True
      Set pres1 = pptApp.Presentations.Add
End With
Set Slide1 = pres1.Slides.Add(1, ppLayoutText)
With pptApp
.ActivePresentation.SlideMaster.HeadersFooters.SlideNumber.Visible = msoTrue
For Each s In pptApp.ActivePresentation.Slides
s.DisplayMasterShapes = True
s.HeadersFooters.Footer.Visible = msoTrue
s.HeadersFooters.Footer.Text = "[COLOR=red]What do you want to say[/COLOR]"
s.HeadersFooters.SlideNumber.Visible = msoTrue
Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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