How to assign Textshape 1 as the title? - vba

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

Related

How to find the label of a shape on a Powerpoint slide

Can someone please point me in the right direction to finding the label Powerpoint uses for each shape, active x control, etc... I've researched till I'm blue in the face. Here's what I'm talking about:
I have a very simple slideshow that asks a question in a text box. Just below the question I placed an active x control text box to get the user's answer. All I want to do is take the answer and append it to a text file. Here's the code:
Public Sub WriteAnswerToFile(slideNum As Integer, shapeNum As String)
Dim filePath As String
Dim objFSO As FileSystemObject
Dim objFile As Variant
filePath = "C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt"
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Batch Files\Powerpoint\ButtonPushes\AnswerFile.txt", ForAppending)
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).TextFrame.TextRange)
objFile.Close
End Sub
From each slide, I pass the slide number and the shape designator to the sub routine. The shapeNum is a string because I found that it worked (no better reason than that) for me to pass something like "TextBox 1" as the param. It all works absolutely great if I know the Shape(designator); as in Shape(TextBox1). For the life of me I cannot figure out how to pass the text input by the user into the active x control text box. I have no idea what the designator is. The property sheet for the text input box calls it TextBox1. The Code sheet calls it TextBox1. When I pass that parameter, it prints the question I asked, not the answer, to my text file. I don't know how to call the input text box in my code.
My code prints "How did you hear about us?" to my text file when my code runs with Call WriteAnswerToFile(2, "TextBox 1"). I'm sure that textbox is called textbox 1; it's the first textbox on the slide. I just don't know what Powerpoint labels the user input box.
If there is some sort of Powerpoint scripting or layout page that will define all the shapes in the slidewhow, I'd sure like to be pointed that direction.
You just need to refer to the form part of the Object since this is not a normal shape.
objFile.WriteLine (Application.ActivePresentation.Slides(slideNum).Shapes(shapeNum).OLEFormat.Object.Text)
To clarify from your comment. I think that you have two "Text Box 1". One is "TextBox 1" (note the space) which is the normal textbox and the ActiveX control is "TextBox1" (no space).
If I create a new blank slide and first add a normal text box and then an ActiveX textbox and then run the following code:
For Each shp In Slide2.Shapes
Debug.Print shp.Name
Next shp
The Immediate window will show the following:
TextBox 1
TextBox1
By chance I happened to stumble upon the simplest answer to my question of "finding the label Powerpoint uses for each shape, active x control, etc.."
I am using the Office 16 (Office 365) suite that contains Powerpoint and would not be certain this feature is avaiable to other versions.
On the Home tab in Powerpoint there is an Editing submenu that contains a Select function. As pictured here:
When you click on Select, another submenu appears that shows a Selection Pane function. If you click on that, the selction pane shows up on the right hand of the screen. In that pane you will see all of the objects on the current slide and the names Powerpoint has given to each of them.
It shows there, the discrepancy I was having with calling TextBox(Space)1 and TextBox(NoSpace)1.
This works to be much more expedient for me to grab the name of the shape I want to call in my VBS Scripts.
I am thankful; however, for the time and frustration #Diederik Sieburgh saved me in allowing me to move forward with my project as it is now 2 weeks later that I stumbled upon this information.

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.

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

Branching Slides in PowerPoint (VBA)

I am trying to create a back button but using hyperlinks it simply just takes me to the previous page and ends up in a loop... e.g. if I have slide 1 which has links to slide 3, 4 & 5 then slide 3 links to 6 & 7. If I'm currently on slide 7 and click back it successfully takes me back to slide 3 but then I want to click back and end up at slide 1 rather than back to slide 7 (hopefully I'm making some sense!).
I presume the only way for me to do this is with VBA can anyone give me some advice on best way to create a back button? (I'm using PowerPoint 2007)
I was struggling with a similar problem today and made a little "breadcrumb"- generator for powerpoint. There is no link feature yet, but you can implement it if you like:
Github Project
Essential parts of the code
Public Sub breadcrumbs(ByVal count As Integer, ByRef titles() As String)
Dim cntr As Integer
Dim content() As String
Dim margin As Integer
Dim width As Integer
'----------------------------
' Set Titles
content = titles
cntr = 0
' Set width
width = ((Application.ActivePresentation.PageSetup.SlideWidth - (margin * count * 2) - 20) / count) - 50
' Loop through all slides
For Each sld In Application.ActivePresentation.Slides
' generate breadcrumb for each title
For Each con In content
sld.Shapes.AddShape(1, (50 + (width * cntr)), 15, width, 50).TextFrame.TextRange.Text = con
cntr = cntr + 1
Next con
cntr = 0
Next sld
End Sub
It sounds like you want a 'breadcrumb trail' of visited slides, instead of a simple back button. Thus you need a way to preserve the trail.
This could be addressed with a dynamic array. New browsing would add records to the array. Your "Next" and "Previous" locations would be found by moving up or down the array. You'll have some mild logic puzzles. I hate to refer you a generic resource, but I'm out of specifics and an overview may be helpful.
UPDATE: I've wanted this in the past for MS Access, and thought I'd readily find a snippet solution. But now I go to search (thinking it will convert over for you easily as well), and I don't find anything. This is surprising because I imagine it would be fun to built. Or ... it's harder to build than I anticipate.
There is a really cumbersome way to do this in PPT directly with no programming. You'll need "forward-facing slides" and 2 sets of "backward-facing slides". Backwards ones are two types - direct-back and home-back. They can all be identical, but make the backward ones hidden (e.g. instead of "Slide 3" you'll need "Slide 3a" and "Slide 3b" and "Slide 3c".). They are hidden so that when you progress through normally, you won't see them, but when you link to them, they will appear. Your link list on the "a" slides should always point to the "b" slides and your "b" slides will point to the "c" slides. Your hyperlinks on "back button" on "a" slides should be "previous slide" and on the "c" slides should be "last slide viewed" and on "h" slides should be "first slide" (use 'action' to set this instead of 'hyperlink').
It takes a while to work through, but it can be done.

Renaming Objects in PowerPoint

Probably a very stupid question but I can't figure how to rename an object in PowerPoint.. For example, all my Graphs are called by default "Graph 1" etc.
Could someone help me on that?
Thanks!
In PowerPoint 2007 you can do this from the Selection pane.
To show the Selection pane, click on the Home tab in the ribbon, then click on Arrange and then 'Selection Pane...' at the bottom. The Selection pane will open on the right. (Or press CTRL+F10)
To rename an object, first select the object and then double click on the object name in the Selection pane and you will be able to type the new object name.
(This answer assumes you are merely assigning more meaningful names during development, so your other code that references the objects can be more readable).
Put the code below into a sub, then run it from the slide in question. Each shape will be selected in turn, so you can see what shape is being referenced. An input box will tell you the current name and ask you for a new name. If you cancel or OK a zero-length input, the old name will stay in place. There is no name entry validation in this code, so be sure you type only valid names. After running it once, you can run it again just to check that the names you typed in the first round were applied to the object you intended.
The loop will cover all objects on the current slide, so if you want to process multiple slides, you have to run this separately on each slide. Every object on the slide is considered: title, drawing objects, groups, embedded pictures, equations, etc. etc. - just don't type a new name for objects that you don't care.
After your development is finished, best hide (Private Sub) or erase this code, so your users don't change object names by mistake.
Dim s As Integer, NewName As String
With ActiveWindow.Selection.SlideRange
For s = 1 To .Shapes.Count
.Shapes(s).Select ' So you can see the object in question
NewName = InputBox(.Shapes(s).Name) ' Tell what current name it is and ask for new name
If Len(NewName) > 0 Then .Shapes(s).Name = NewName ' If you typed a new name, apply it
Next s ' 1 To .Shapes.Count
End With ' ActiveWindow.Selection.SlideRange
Thanks for your help but actually I am just doing it using VBA...
ActiveWindow.Selection.ShapeRange(1).Name = "newname"
Cheers