Number only visible slides using master slide - vba

I want hidden slides in my presentation to be skipped in the slide numbering. I do, however, have a master slide that has text boxes as the footer and slide number, and this number is what I need to be updated when slides are hidden/unhidden. This is a picture of the footer in the master slide:
I already tried the solution posted here but it does not work.
VBA : Number the slide if they are visible
I think it's because of the master slide. This is the error I get:
Run-time error '-2147188160 (80048240)':
HeaderFooter (unkown member) : Invalid request.
And when debugging it it highlights this line of code as the problem:
diapo.HeadersFooters.Footer.Text = CStr(x)

Related

PowerPoint VBA Slide Index Where VBA Code Resides

I need to set the True/False value of an option button in PowerPoint VBA, like this: ActivePresentation.Slides(3).Shapes("optnUrgencyHigh").OLEFormat.Object.Value = True
The above works great, if the option button is on slide 3, but if someone inserts a slide or 10, before slide 3, this no longer works. I cannot seem to find a way to reference the slide number, for the particular code to reference. I can get the slide number that is currently displayed, but not the slide number where the VBA code resides.
This is further complicated in that the user could have 1 to n number of duplicates of the slide, so while I have the VBA in each copy of the slide, knowing the slide number reference, instead of a hard 3, for example, is eluding me.

How do I change the value of the SlideMaster.Height in PowerPoint 2016 VBA?

I'm trying to automate the process of changing the height in the Slide Size dialog in the Slide Master system with VBA. When I try to change it, VBA informs me that I'm not permitted to assign a value to ActivePresentation.SlideMaster.Height because it is read-only.
I've studied the ActivePresentation object tree and have figured out to acquire the height value (with ActivePresentation.SlideMaster.Height), but the following line results in a Compile Error:
ActivePresentation.SlideMaster.Height = 1189
Changing the SlideHeight with...
ActivePresentation.PageSetup.SlideHeight = 1189
does change the height of the slide, but it doesn't have the same effect as changing the height through the Slide Master system. The primary question at this stage is if it's possible to change ActivePresentation.SlideMaster.Height with VBA, or is the Read-Only status immutable?
Sub test()
ActivePresentation.SlideMaster.Height = 1189 'Compile Error...can't assign to read-only property
ActivePresentation.PageSetup.SlideHeight = 1189 'Changes the height of the slides, _
but doesn't change the size of text within Shape elements like I need it to do.
End Sub
Here's some background...
Through a bit of trial and error, I've determined that if I change the dimensions of the slides using the slide master, the default text for Shapes is set how I want it (at pitch 18). If I don't change the dimensions in the Slide Master, the text for Shapes remains at 31. Even if a new shape is created, the font is changed to 18 and that shape is set as the default shape, if text is pasted onto the slide (with CTRL-v or Paste Special-Unformatted Text), the shape that gets created has a text-size of 31.
Just to be clear, if the default is set to 18 and I create another new Shape via Insert>Shapes, then that new shape is automatically set to 18. It's only when I paste text (using either CTRL-v or Paste Special - Unformatted) directly on the slide does it become 31.
The only thing that does what I want is making a slight change to the Slide Master Slide Size. Changing the height from 1188 to 1189 forces all of the shapes on all of the slides to go from 31 to 18. Any new text that gets pasted in the slide comes in as a shape containing 18 text.
The reason I'm posting this on Stack Overflow and not on Super User is because I have to automate this change...we have thousands of presentations to modify.

PowerPoint VBA - hyperlink - change text to display to slide number

I have set up an index for a presentation with hyperlinks to the slide number for each item to go to. The hyperlink 'text to display' has been manually set to the slide number. How would I go about updating this item using VBA if I add or remove a slide from the presentation?
Update: I've tried a couple of methods that almost work see this link for a ...
Mock Up of TOC to be updated

Vba code to delete all slides with a blank layout powerpoint?

Looking for an example vba code that deletes all slides with a blank layout.
I am trying to create a catalog using a UserForm. The user selects which products they want to look at and the code deletes the slides of the products they don't want to look at.
The problem is that if I delete the array of slides specific to a product, it changes the total number of slides and then the other slide number arrays no longer contain the slides specific to the other products.
I was thinking I would add blank slides in place of the undesired slides and then delete all of the blank slides at the end.
I am open to other ideas and suggestions. Thank you for your time and assistance.
It sounds as though you're working with arrays of SlideNumber or SlideIndex.
Never bother with SlideNumber for various reasons.
And in this case, SlideIndex will change after you delete slides.
Instead, either work with arrays of Slide objects or instead of SlideIndex, use an array of SlideId ... SlideIds are assigned when the slide is created and never change.
Example of how to find a slide from its SlideID, in this case, 258 arbitrarily:
Dim oSl As Slide
Set oSl = ActivePresentation.Slides.FindBySlideID(258)
MsgBox oSl.SlideIndex

Using replace function with VBA loses field code information

I need to use VBA to replace part of a textbox in the template of a PowerPoint presentation. The same box contains a field code (is that the right phrase?) for the slide number.
When I execute the following code on every shape oSh in the template:
If oSh.HasTextFrame Then
oSh.TextFrame.TextRange.Text = Replace(oSh.TextFrame.TextRange.Text, searchString, newString)
End If
the information about the field code disappears - slide numbering is broken.
Example, if the shape had "this is slide number " followed by the slide number field code, then if I replace "this is slide number" with "slide", the text will show as "slide <#>".
When I use the PowerPoint "replace" function, the functionality is preserved (slide numbering still works). How is it different? And more importantly - how do I get the substring replaced without destroying the slide numbering?
"When I use the PowerPoint "replace" function, the functionality is preserved (slide numbering still works). How is it different? And more importantly - how do I get the substring replaced without destroying the slide numbering?"
Doesn't the the first sentence answer the question posed in the second? ;-)
For example, this snippet will do the replacement you ask for on each shape on each slide in the presentation:
Dim oSl As Slide
Dim oSh As Shape
For Each oSl In ActivePresentation.Slides
For Each oSh In oSl.Shapes
oSh.TextFrame.TextRange.Replace "This is the slide number", "Slide"
Next
Next
Using PPT's own Replace function solves a number of other problems as well ... it does a pretty good job of retaining mixed formatting, for example.
How's it different from the native VB/VBA Replace function? App-specific functions like this can app-aware, ie, can special-case for features that the specific app supports.