Take the name that appears while setting an hyperlink with vba - vba

When you want to add an hyperlink in powerpoint you can access to it for example with right click in the shape that you want and selecting "Hyperlink...". Then appears this dialog box:
As you can see there appears the slide names but those slides numbers are not the same that you can get with ActivePresentation.Slides(sliNum).Name. How can I get those names with VBA?

?ActivePresentation.Slides(75).Shapes.Title.Textframe.TextRange.Text
Should return Marketing Plan Overview in your case

This seams to be slide index and title shape text or slide name if title not found:
Function SlideTitle(ByVal Slide As Slide) As String
If Slide.Shapes.HasTitle Then
SlideTitle = Slide.SlideIndex & ". " & Slide.Shapes.Title.TextFrame.TextRange.Text
Else
SlideTitle = Slide.SlideIndex & ". " & Slide.Name
End If
End Function

Related

How to apply a hyperlink to another slide in the document?

Is it possible to apply a hyperlink to another slide in the document using VBA?
I have a document that has labelled hyperlinks.
I right-click each one to assign a link which is taking a long time and open to me making mistakes.
Could a loop routine apply the appropriate hyperlinks?
Here's a simple macro for setting the hyperlink to a slide in the same presentation:
Sub SetHyperlinkToSlide()
With ActiveWindow.Selection.ShapeRange.ActionSettings(ppMouseClick).Hyperlink
.Address = ""
.SubAddress = "257,2,Title"
.ScreenTip = ""
.TextToDisplay = ""
End With
End Sub
The 3 numbers in Subaddress are the SlideID, the SlideIndex and the SlideTitle parameters. You don't have to include all three, but you do have to include all the commas. So If you want to jump to a known slide title:
.SubAddress = ",,Known Slide Title"

How change the style of a shape-text in vba?

I changed the size of text with the following line of code
shp.CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU = " 3pt"
I'd like to change the style (to Bold) and color of the shape text with the same pattern of code ?
I didn't find the exact "formula", would you know how I could do that ?
Thank you very much in advance
Edit : I found this line for the color :
shp.CellsSRC(visSectionCharacter, 0, visCharacterColor).FormulaU = "THEMEGUARD(RGB(255,0,0))"
I'm not sure why there is no enumeration for setting the Style. In any case, it's Column 2 in the shape properties. So use
shp.CellsSRC(visSectionCharacter, 0, 2).FormulaU = 17
to set your text to Bold.
How do I know this you ask? Based on the Microsoft reference on Understanding the Shape Sheet, there is a helpful snippet of code to use.
First, select the shape in your drawing that you want to see information about the properties. Then open up the Shape Properties window in the Visio editor (not in the VBE) -- you can get there by viewing the Developer ribbon, then click on the Show ShapeSheet icon
In the shape properties window, scroll down until you see the Characters section. You MUST select one of the cells in the properties window. The example here has selected the Style column.
Once you have done this, then run the following code snippet below and you'll get the information you need in the Immediate Window of the VBE.
Public Sub DebugPrintCellProperties()
' Abort if ShapeSheet not selected in the Visio UI
If Not Visio.ActiveWindow.Type = Visio.VisWinTypes.visSheet Then
Exit Sub
End If
Dim cel As Visio.Cell
Set cel = Visio.ActiveWindow.SelectedCell
'Print out some of the cell properties
Debug.Print "Section", cel.Section
Debug.Print "Row", cel.Row
Debug.Print "Column", cel.Column
Debug.Print "Name", cel.Name
Debug.Print "FormulaU", cel.FormulaU
Debug.Print "ResultIU", cel.ResultIU
Debug.Print "ResultStr("""")", cel.ResultStr("")
Debug.Print "Dependents", UBound(cel.Dependents)
' cel.Precedents may cause an error
On Error Resume Next
Debug.Print "Precedents", UBound(cel.Precedents)
Debug.Print "--------------------------------------"
End Sub
This will tell you the Section, Row, and Column to use when you call CellsSRC. What I did was to figure out the property, then I manually set the text to BOLD and viewed the results of DebugPrintCellProperties again to see that the FormulaU = 17 for bold.

VBA code for giving slides a constant name

I am trying to reduce the effort needed to keep a certain slide (lets call it SlideXYZ) up to date. SlideXYZ is an important content slide that can be found in multiple slide decks. I initially created slide objects that updated automatically when a change was made in the "source slide". However, slide objects unfortunately don't contain animations (they are simply a snapshot of the actual slide). I am now trying to write a VBA script that will search and replace SlideXYZ in each deck with a newer version of SlideXYZ. However, the slide number is dynamic (it changes when a new slide is added above). I need a static, constant reference to SlideXYZ.
I thought of copying SlideXYZ into all presentations once and then using the Slide.Name property to find all instances of it once an update is needed.
However, it appears that the Slide.Name is reassigned by powerpoint each time the slide is pasted into a new presentation. I need a reference that will not change so that I can find and replace SlideXYZ.
#Asger's suggestion would work but a more consistent approach (IMO) would be to use tags. Any presentation, slide, or shape on a slide can have one or more bits of text attached in the form of a tag.
For example:
ActivePresentation.Slides(1).Tags.Add "SlideIdentifier", "Bob"
will create a tag named SlideIdentifier with a value of Bob on slide #1 in the current presentation. These tags will travel with the slide, wherever it goes.
This page on the PowerPoint FAQ that I maintain has more info on using tags:
http://www.pptfaq.com/FAQ00815_Working_with_Tags_-and_a_bit_about_Functions-.htm
As you already found out: Neither SlideIndex, SlideNumber, SlideID nor Name can be used to identify a copied slide.
You may work with the "alternative text" of a characteristic shape to identify a slide:
Just do a right mouseclick on the shape and edit its alternative text.
Also slide notes may help to identify a slide.
Following prints some slide information to your debug window:
Private Sub IdentifyMySlide()
Dim myslide As PowerPoint.Slide
For Each myslide In ActivePresentation.Slides
Debug.Print "Index: " & myslide.SlideIndex,
Debug.Print "Number: " & myslide.SlideNumber,
Debug.Print "ID: " & myslide.SlideID,
Debug.Print "Name: " & myslide.Name,
If myslide.Shapes.Count > 0 Then
Debug.Print "Alternative ShapeText: " & myslide.Shapes(1).AlternativeText,
End If
If myslide.HasNotesPage Then
If myslide.NotesPage(1).Shapes.Count > 0 Then
If myslide.NotesPage(1).Shapes(1).HasTextFrame Then
Debug.Print "Notes: " & Left(myslide.NotesPage(1).Shapes(1).TextFrame.TextRange.Text, 10)
Else
Debug.Print
End If
Else
Debug.Print
End If
Else
Debug.Print
End If
Next myslide
End Sub

How to change a specific textbox in a powerpoint slide master

I have a powerpoint that uses different Master layouts on the slide Master. Every time we do an update, a specific textbox on a specifc Master slides needs to be updated. I would like to do so with a macro.
IE I have a slide master with a Generic Title_Slide and 2 variations under that. It has a "Generic Bullet_slide" with 10 variations under that.
on the "Generic Bullet_Slide" there is a textbox that contains two lines:
"CONFIG. MGR: [your name], [your code], [your phone #]"
"FILE NAME: [name of file]"
every time we send the project out, we need to update the fields in [] manually. If we forget its bad news.
I have seen how to loop through all slides, then all shapes to find text boxes. Can I find a boxs that specifically has those words in it ("CONFIG. MGR:" and "FILE NAME:") ?
Can I search "layout" slides only? how do I target anything on the layout slide instead of a normal slide?
thanks a bunch.
You can use the object named 'ActivePresentation.Designs(x).SlideMaster.CustomLayouts' to access each custom-layout slide in SlideMaster Designs. (You can have more than 1 design in a presentation.)
Accessing sub-objects in the custom-layout slides is just like dealing with those in the normal slides.
I think you can try the following automation code:
Option Explicit
Option Compare Text 'Ignore Upper/Lower case
Sub UpdateCustomLayouts()
Dim DSN As Design
Dim CL As CustomLayout
Dim shp As Shape
Dim mName As String, mCode As String, mPhone As String, fName As String
'First, change following variables before running this macro
mName = "Your name"
mCode = "Your code"
mPhone = "0123456789"
fName = ActivePresentation.Name
'Loop each customlayouts
For Each DSN In ActivePresentation.Designs
For Each CL In DSN.SlideMaster.CustomLayouts
For Each shp In CL.Shapes
If shp.HasTextFrame Then
'find and update textboxes
With shp.TextFrame.TextRange
If .Text Like "CONFIG. MGR:*" Then
.Text = "CONFIG. MGR: " & mName & ", " & mCode & ", " & mPhone
ElseIf .Text Like "FILE NAME:*" Then
.Text = "FILE NAME: " & fName
End If
End With
End If
Next shp
Next CL
Next DSN
End Sub
As I mentioned, first change variables like 'mName, mCode, mPhone, fName' before running.

Selecting visio shape and running add-in for the selected shape

I have created a visio add-in using vb.net. The add-in, when clicked, shows a form which is used to insert shape data rows for a selected shape.
Process:
Drop shape on page >> Select the shape (if not selected) >> Click the add-in button >> Windows form shows up
This works perfectly when I drop the first shape. But when I drop another shape from the same master and click the add-in button, the form does not show up.
I have this code for it:
Dim xPS as Visio.Shape
xPS = Globals.ThisAddIn.Application.ActiveWindow.Selection.PrimaryItem
If xPS Is Nothing Then
MsgBox("ERROR: " & vbCrLf & "No 'AA' shape selected. Please select an 'AA' shape and rerun the command")
Exit Sub
Else
'If a shape other than 'AA' is selected, a message box is displayed with error description.
If Left(xPS.Name, 2) <> "AA" Then
MsgBox("ERROR: " & vbCrLf & "Incorrect shape selected." & vbCrLf & "Please select 'AA' shape and rerun the command.")
Exit Sub
Else
xCT.Show() 'Shows the user form
End If
End If
I have a doubt that I am not using the correct syntax for selected shape.
xPS = Globals.ThisAddIn.Application.ActiveWindow.Selection.PrimaryItem
Can someone please tell me why the form does not show up for second shape, but it does for the first one?
Thanks for the help.
Miki