Checking slide name already exists

C

cvil0603

Does anyone know how to check if a slide name already exists, I'm using
macro to add new slides and assigning slidenames from an xml file. Any
suggestions?

part of the code:

For Each rootNode In root
Set statusNode = rootNode.SelectSingleNode("status")
statusName = statusNode.FirstChild.nodeValue

Set groupNode = rootNode.SelectSingleNode("group")

Set titleNode = rootNode.SelectSingleNode("title")

Set categNode = rootNode.SelectSingleNode("category")
categName = categNode.FirstChild.nodeValue

Set linkNode = rootNode.SelectSingleNode("hyperlink")
Set descNode = rootNode.SelectSingleNode("description")
Dim theSlide
Dim findSlide

If Not groupNode Is Nothing Then
groupName = groupNode.FirstChild.nodeValue
linkName = linkNode.FirstChild.nodeValue
If Not ActivePresentation.slides.Count < 3 Then
For Each theSlide In ActivePresentation.slides.Range

'MsgBox theSlide.Name & ":" & theSlide.SlideID & ": " &
groupName
If Not theSlide.Name = linkName Then ' <<<------ (doesn't
work) --->>>

With
ActivePresentation.slides.Add(ActivePresentation.slides.Count + 1,
ppLayoutBlank)
.Name = linkName
'MsgBox .Name

With
..Shapes.AddTextbox(msoTextOrientationHorizontal, 40, 40, 600, 30)
.TextFrame.TextRange.Text = groupName &
linkName
.Width = 300
.Name = groupName
.TextFrame.TextRange.ParagraphFormat.Alignment
= ppAlignLeft

With .TextFrame.TextRange.Font
.Name = "Verdana"
.Size = 32
.Color = RGB(0, 25, 101)
End With
End With
 
D

David M. Marcovitz

It looks like you've got the right idea. Put your Dim statements at the
beginning of your Sub and be sure to Dim linkNode as String. In your For
Each statement, you shouldn't need .Range, but I don't think it will
hurt.

The following code works for me (it just asks for the user to input a
name because I don't have the XML file):

Sub DoesItMatch()
Dim guessName As String
Dim sld As Slide

guessName = InputBox("What name are you checking?")
For Each sld In ActivePresentation.Slides
If sld.Name = guessName Then
MsgBox "We have a match"
End If
Next sld
End Sub


--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

(e-mail address removed) wrote in @i40g2000cwc.googlegroups.com:
 
S

Steve Rindsberg

Does anyone know how to check if a slide name already exists, I'm using
macro to add new slides and assigning slidenames from an xml file. Any
suggestions?

You could iterate through the presentation's .Slides collection and check each
name to see if it matches or more directly, see if it errors when you try to
create a reference to the slide:

Function IsSlideNamed(sSlideName as String) as Boolean
Dim oSl as Slide
On Error Resume Next
Set oSl = ActivePresentation.Slides(sSlideName)
' if no error, there's a slide by that name
If Err.Number = 0 Then
IsSlideNamed = True
Else
IsSlideNamed = False
End If
End Function
 
Top