Active CustomLayout slide - vba

How can I get the index number of the active/current CustomLayout that is being displayed in the Slide Master view?
I want to be able to have the user change the current CustomLayout's name.
Thanks!

The solution provided by #steveRindsberg in the comments worked great:
ActiveWindow.View.Slide.Name

Related

Navigate to PPT Slide by its ID or Name instead of Number

ActivePresentation.SlideShowWindow.View.GotoSlide x requires us to enter the slide number, which is varying. If I refer it to Slide Number 3 and then move the position of Slide 3, the code wouldn't refer to that slide anymore.
How do I overcome this by referring to the SlideID or SlideName instead of Slide Number.
Thank you.
If I understand the question correctly, you want to be able to go to a particular slide in the presentation regardless of where it may appear in the presentation (ie because other slides have been added before it or it's been moved to a different position).
If so, you could tag the presentation with the slide's SlideID:
ActivePresentation.Tags.Add "IndexSlide", Cstr(lSlideID)
(where IndexSlide is any convenient name you've assigned to the slide; you can have multiple tags for different slides you want to track. And lSlideID is, of course, the slide's SlideID
You'd need to write a function to retrieve the slide's SlideIndex, given the SlideID and call it like so (aircode ... you might have to move/remove a paren or two):
ActivePresentationSlideShowWindow.View.GoToSlide ( _
SlideIndexFromSlideID(cLng(ActivePresentation.Tags("IndexSlide")))
This gets the tag named IndexSlide from the presentation which is the SlideID of IndexSlide, converts it to a Long (tags are strings), passes it to your SlideIndexFromSlideID function, which returns the slide's current SlideIndex ... for you to GoToSlide with.
[Later: adding the needed function for returning SlideIndex]
Function SlideIndexFromSlideID(lSlideID As Long) As Long
SlideIndexFromSlideID = ActivePresentation.Slides.FindBySlideID(lSlideID).SlideIndex
End Function

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.

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

Start a Powerpoint slideshow from a slide without showing the first slide for a brief moment

I think the title is self - explanatory.
I want to use a VBA macro to start the slideshow from a specific slide, for example the 5th one.
If i use
ActivePresentation.SlideShowSettings.Run.View.GotoSlide 5
it flashes the first slide for a brief moment. I want to get rid of that.
I'm thinking that it might be possible to show the slideshow with a black screen only, change the slide and then show the slideshow correctly, but I don't know how to start it as a black screen.
Try this:
With ActivePresentation.SlideShowSettings
.RangeType = ppShowSlideRange
.StartingSlide = 5
.Run
End With
edit: .RangeType = ppShowSlideRange was missing.

How to get the master layout slide name

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.