PowerPoint VBA Help Please...

jmmckillen

New Member
Joined
Jan 9, 2021
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
I am trying to set the font size on a textbox that I just added to all slides and have run into nothing but trouble. The purpose is to number the slides like so (SLIDE 5 of 25, and so on). Please advise...

Public Sub URSlide_of_Slides()
''' upper left of slide
''' Slide height: 540
''' wSlide width: 960
''' nSlide width: 720

Dim sldHgt As Single, sldWdt As Single
sldHgt = ActivePresentation.PageSetup.SlideHeight
sldWdt = ActivePresentation.PageSetup.SlideWidth
'
Dim mySlide As Slide
For Each mySlide In ActivePresentation.Slides
If frmSliders.CheckBox1.Value = True Then
If mySlide.SlideIndex = 1 Then GoTo nextSlide
End If
With mySlide.Shapes
.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=sldWdt - 120, Top:=sldHgt - 540, Width:=120, _
Height:=35).TextFrame.TextRange.Text _
= "SLIDE " & CStr(mySlide.SlideIndex) & " of " _
& CStr(ActivePresentation.Slides.Count)
End With
nextSlide:
Next mySlide
'
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I am trying to set the font size on a textbox that I just added to all slides and have run into nothing but trouble. The purpose is to number the slides like so (SLIDE 5 of 25, and so on). Please advise...

Public Sub URSlide_of_Slides()
''' upper left of slide
''' Slide height: 540
''' wSlide width: 960
''' nSlide width: 720

Dim sldHgt As Single, sldWdt As Single
sldHgt = ActivePresentation.PageSetup.SlideHeight
sldWdt = ActivePresentation.PageSetup.SlideWidth
'
Dim mySlide As Slide
For Each mySlide In ActivePresentation.Slides
If frmSliders.CheckBox1.Value = True Then
If mySlide.SlideIndex = 1 Then GoTo nextSlide
End If
With mySlide.Shapes
.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=sldWdt - 120, Top:=sldHgt - 540, Width:=120, _
Height:=35).TextFrame.TextRange.Text _
= "SLIDE " & CStr(mySlide.SlideIndex) & " of " _
& CStr(ActivePresentation.Slides.Count)
End With
nextSlide:
Next mySlide
'
End Sub
I just found my own answer! I would have been quicker had MS not pulled the macro recorder from PowerPoint starting with Office 2007! Anyway, here is what seems to work:

Public Sub URSlide_of_Slides()
''' upper left of slide
''' Slide height: 540
''' wSlide width: 960
''' nSlide width: 720
Dim sldHgt As Single, sldWdt As Single
sldHgt = ActivePresentation.PageSetup.SlideHeight
sldWdt = ActivePresentation.PageSetup.SlideWidth
'
Dim mySlide As Slide, shp As Shape
For Each mySlide In ActivePresentation.Slides
If frmSliders.CheckBox1.Value = True Then
If mySlide.SlideIndex = 1 Then GoTo nextSlide
End If
'
Set shp = mySlide.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=sldWdt - 150, Top:=sldHgt - 540, Width:=150, Height:=35)
With shp.TextFrame
.TextRange.Text = "SLIDE " & CStr(mySlide.SlideIndex) & " of " & CStr(ActivePresentation.Slides.Count)
.TextRange.Font.Size = 15
.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignRight
End With
nextSlide:
Next mySlide
'
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,358
Messages
6,171,625
Members
452,412
Latest member
thomasleysen531

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