How to get the master layout slide name - vba

I'm populating PowerPoint slides with data from an Excel spread sheet. At the moment, I'm accessing the slide using the page number:
Set mySlide = PowerPointApp.ActivePresentation.Slides(1)
Using the Master View option in the UI, you can rename the slide. How can I find the slide using that name?
Thanks,
Carlo.

ActivePresentation.Slides(i).Master.Design.Name
It is the name you see for the theme, in the master view for the slide.
layoutIndex = ActivePresentation.Slides(i).CustomLayout.Index
It is the current layout of the slide in the above theme.
ActivePresentation.Slides(i).Master.Design.Parent.CustomLayouts.Item(layoutIndex).Name
It is the layout name of the currently selected layout of the slide.
it is the VBA, what you can say :-).

Using the Slide.Name property will define the name of the slide and allow it to be called using:
ActivePresentation.Slides("Name")
per the MSDN

So, what I wanted was a way to uniquely identify a PPT slide through VBA. The problem is that I still need to be able to identify that slide if it is copied to another PPT document.
So, what I found I had to do was:
create a text box on each page and hard-code the text to be something like "Slide:Cover" or "Slide:QuarterlyResults", etc.
loop through each slide
find "Slide:" and strip it out to get the page title. That way, if the slide is copied to another PPT document, the name goes with it.
create a Dictionary that uses the Slide.SlideID as the key and the page title as the value.
Then what I do is loop through the slides, get the SlideID, use the Dictionary to get the page title and use a Select statement to map to the proper method to process the slide.
Yeah, I know... it's an icky hack, but it's the only way I could think of doing it.
Thanks for you help,
Carlo.

Related

PowerPoint VBA add shape event/ add shape with tag value

i'am currently trying to add a small function to PowerPoint using VBA, my goal is to create a gadget that works kind of like Photoshop graphics layer.
My plan is to add a layer name Tag on each shape that is drawn by user, so later I can parse through every item by loop and preform lock/unlock, show/hide shapes based on it's tag value, such as:
Sub add_shape_with_layer_tag()
Set islide = ActivePresentation.Slides(1)
Set ishape = islide.Shapes.AddShape(msoShapeRectangle, 5, 5, 80, 60)
ishape.Tags.Add "Layer", "1"
End Sub
Sub show_hide_layer_one_shapes()
Dim active_slide As Slide
Set active_slide = ActiveWindow.View.Slide
For Each ishape In active_slide.Shapes
If ishape.Tags("Layer") = "1" Then
ishape.Visible = Not (ishape.Visible)
End If
Next ishape
End Sub
However, I couldn't found a way to achieve this, so I would like to ask whether there's a method that provides following functions?
override add shape function so I can sneak tag value in to shape every time user drawn a shape
catch add shape event (if this thing did exist) so i can add tag to the last added item
a way to set a default tag value to shape, just like setting default shape color/line width
or is there any better options that is also viable?
thanks.
20200728
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Not totally an answer, sorry SO, but comments don't allow enough scope for this. So ...
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
Ah, so you're creating your own "pseudo-layers". That wasn't clear. Thanks for the add'l info. As it happens, I have a selection manager add-in that works very similarly to what you're proposing.
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
The SelectionChange event should get you there. When it fires, you'll need to check first to see if the current selection is a shape or something else. If a shape, check to see if its .Index = current slide's .Shapes.Count and also to see if you've already tagged it. If no tag AND if it's the correct index, it'll be a newly added shape. If you're tagging ALL shapes, you may only need to check to see if the .Tag(name) is blank.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Why not save any needed slide or presentation level info as further slide- or presentation-level tags? PPT can absorb quite a lot of info as tags w/o getting cranky.

Applying layout to a slide from specific Master

I need to apply a specific layout to a slide from a specific master.
Suppose I have two master templates in the deck and I want to apply "Title Only" layout from the second master.
The code is running but layout is not changed.
ActivePresentation.Slides(11).Layout = ppLayoutTitleOnly
ActivePresentation.Slides(11).Select
Application.CommandBars.ExecuteMso ("SlideReset")
Two screenshots.
The .Layout property is only useful for applying default Microsoft layouts. In most customized presentations such as yours, you can't count on any of those layouts being that standardized. Instead, use the .CustomLayout property, which, despite its name, actually applies any layout, custom or not.
The syntax for accessing a slide master is non-intuitive:
Sub PickSlideLayout()
ActivePresentation.Slides(1).CustomLayout = ActivePresentation.Designs(2).SlideMaster.CustomLayouts(6)
End Sub
.Designs(2) gets you the second slide master. .CustomLayouts(6) gets the Title Only layout in a standard presentation. CustomLayouts doesn't take a string, so you can't use the layout name. Instead you have to refer to the layout number or index.

How to assign Textshape 1 as the title?

With Office 2016 PPT, after sharing a PPT file and getting it back, it now has retained titles on the slides but they are now "TextShape 1", are in the correct location (top of slide), and do not show up as titles in the outline view, etc.
Merely resetting the slides overlays empty boxes.
How can I make "TextShape 1" on each of the slides to be seen as the Title for the respective slides? A redefinition? Add a new Title box with the content of "TextShape 1", and delete the old box?
Thanks for the views.
It was not easy as a vba-powerpoint beginner finding my way through the collections and terminology, and certainly time consuming, but I wrote a solution for the limited problem as presented.
You might think you could add a title object, but at least the way I tried, it complained that that could not be done with the current slide layout. I could not figure out how to designate a text box as a Title. So I used vba to set the formats to Titleonly for slides without one, copied the text into it, then deleted the old shape that was overlaid with the new one as below:
Attribute VB_Name = "Module1"
Sub newtitles()
Dim s As Variant
For s = 1 To ActivePresentation.Slides.Count
If Not ActivePresentation.Slides(s).Shapes.HasTitle Then
ActivePresentation.Slides(s).Layout = ppLayoutTitleOnly
' adds a title placeholder too; could not .addtitle to slide without a title in format
ActivePresentation.Slides(s).Shapes.Title.TextFrame.TextRange.Text = ActivePresentation.Slides(s).Shapes(1).TextFrame.TextRange.Text
ActivePresentation.Slides(s).Shapes(1).Delete ' remove redundant box
End If 'about title
Next ' slides
End Sub

Accessing ScreenTip text

I have a long MS Word doc that has many bookmarks/hyperlinks. The only purpose of the bookmarks is to be able to use the screen tips to view additional information about what is bookmarked.
Is there a way to access this screen tip text, and store it in a variable?
Eventually I will use this to create a macro that will change the displayed text to include the screen tip text (so the information can be printed, when necessary).
Here's how to print-to-console all the Hyperlink ScreenTips in your document:
Sub printScreenTips()
Dim link As Hyperlink
For Each link In ThisDocument.Hyperlinks
Debug.Print link.ScreenTip
Next
End Sub
Note: I'm not aware of a way to add a ScreenTip to a bookmark, but you can add a ScreenTip to the hyperlink that points to a bookmark.

Identify Shape on the slide in PowerPoint VSTO API using ID/Title/Whatever

I'm writing a PowerPoint 2010 AddIn. In a nutshell this is what I do:
Create PowerPoint Template (*.potx) with a great deal of defined Layout slides
Write plugin that automates some common tasks that are made after presentation is done. One of them is to insert Agenda Slide (defined as Layout in SlideMaster) as the first slide in every section.
After the Agenda Slide is inserted (that was pretty easy with: newAgendaSlide.MoveToSectionStart(sectionNumber)) I must set the text of two Shape objects (one on the top of the slide, and second one is located in bottom/right corner - let's call the Header & Footer) to the name of current PowerPoint section, on every slide in current section.
And now, I know how to get section's title:
Presentation.SectionProperties.Name(sectionNumber)
and I know how to iterate through Shape objects that are on the Slide object. But I don't know how to access right Shape. I can't be sure that, for instance, that my Header/Footer shape will have Id set to particular value? Is there any way to set some kind of property on Layout's Shape, and then be completely sure that the same property will have the same value on the Slide?
To sum up (and hopefully make it clear): I would like to create a Layout slide (in SlideMaster) with x number of shapes, and be able to access particular slide on real presentation slide.
I would probably insert the Header/Footer shapes myself rather than using PPT's (badly broken) footers.
I'd use tags to identify the shapes you've added. When its' time to manipulate one of them, look to see if there's one on the slide already (testing for tags you've added) and if it's not found, add your own. AirVBA example:
For each oSh in oSlide.Shapes
If Len(oSh.Tags "MyShape") > 0 Then ' its' your footer
Set oFooter = oSh
End If
If oFooter is Nothing then ' not there, add one:
Set oFooter = ... add the shape here
' add the tags
oFooter.Tags.Add "MyShape", "Footer"
With oFooter
' format it, add text, whatever
End with
End if
Next