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
Related
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.
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)
I'm working on creating a PowerPoint template for daily class presentations. In the template I'd like to have a hunk of text that is prominently displayed on the first slide and which repeats at the bottom of the subsequent slides at the bottom in a smaller size. The text will change every day.
The ideas I've had so far:
Use a text field. As far as I can tell, PowerPoint doesn't have anything like a text field that can be dynamically set.
Use a footer - this works and I can modify the master to get the look I want, but I'd really like to be picking up the value of the text from the first page so that edits would be automatically applied and to save the initial step of setting the footer.
Using VBA - I'd be willing to give this a shot, but I've never used VBA and the learning curve seems steep so it would be nice to know if the idea is feasible in VBA.
Can this be done? How would you approach it?
Here's an example of what I'm hoping to be able to do. Ideally the solution would work on both the Mac (2013) and Windows (2016) version of PowerPoint.
You can connect your presentation with an excel file. And running the code in the ppt would pull out the text in the excel file and update the titles instantly.
Create a presentation with a textbox with some temporary text. Put the below code in ppt. save as pptm.
Sub AddMotionPath()
Dim Temp As String
Excel.Application.Workbooks.Open ("D:\Users\Desktop\Book1.xlsx") ' update the path of the excel file
Workbooks("Book1.xlsx").Activate 'activate the file
For p = 1 To 4
Temp = Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("B" & p + 1).Value ' Column B has the titles
ActivePresentation.Slides(p).Shapes(1).TextFrame.TextRange.Text = Temp ' this updates the titles from excel to ppt slide
Next
Excel.Application.Workbooks("Book1.xlsx").Close False 'closes the excel file
End Sub
Let me know if this works for you. You can update the excel file and run the macro in ppt. The text in the slides will be updated automatically.
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
Wondering if there is a macro that could automatically update slide references for objects on other slides.
For instance, let’s say there is a table on slide X. I want to be able to place a text box on slide 5 and say “refer to page X.”
These presentations are printed so using hyperlinks would not work. We do not want to hard code the reference because if we add/delete slides, we do not want to go back and manually update all the references.
My VBA knowledge is very limited. Not sure how to "tag" an object and then reference it.
To tag a shape, assuming it's currently selected:
With ActiveWindow.Selection.ShapeRange(1)
.Tags.Add "TagName", "TagValue"
End With
So for example, select the table and:
With ActiveWindow.Selection.ShapeRange(1)
.Tags.Add "ShapeTag", "Table1"
' the value above should be unique
End With
Hooking the text that you want to update up to the table will be a bit trickier. I'd approach it by adding two tags to the text shape, the first being the text you want to appear in the text box, but with the slide number included as a replaceable parameter; the next tag would be a reference to the shape in question:
With ActiveWindow.Selection.ShapeRange(1)
.Tags.Add "Text", "Refer to page #page#"
.Tags.Add "Shape", "Table1"
End With
To update, you'd run code that checks each shape on each slide and if the shape has Len(.Tags("Shape")) > 0 you'd call a function that looks at each slide/each shape and returns the slide number where it finds a shape tagged "Table1".
You'd then substitute the slide number in place of #page# in the .Text tag and apply that as the shape's .TextFrame.TextRange.Text