Delete Specific Tag

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I delete a specific slide tag? I want to delete empty tags. I've
tried this:

Sub Delete_Empty_Tag()
Dim x As Long
Dim oSl As Slide

Set oSl = ActiveWindow.View.Slide
If oSl.Tags.Count > 0 Then
With oSl.Tags
For x = 1 To .Count
If oSl.Tags.Name(x) = "" And oSl.Tags.Value(x) = "" Then
oSl.Tags(x).Delete
End If
Next ' x
End With
End If
End Sub

But I get this error message:
Compile error: Invalid qualifier Tags(x)
(referring to the line " oSl.Tags(x).Delete ")

I'm not sure how the empty tags got there to begin with, but when I
ShowTags, I see tags for which Name="" and Value="", and I want to get rid of
them. I can't seem to target a single, specific Tag for deletion because
there's a Tags (plural) object, but not a Tag (singular) object to be deleted.

Any ideas?
 
1. You cant have with osl.tags and THEN If osl.tags..
2. To delete tags use .delete (tagname)

so try

Sub Delete_Empty_Tag()
Dim x As Long
Dim oSl As Slide

Set oSl = ActiveWindow.View.Slide
If oSl.Tags.Count > 0 Then
With oSl.Tags
For x = 1 To .Count
If .Name(x) = "" And .Value(x) = "" Then
..Delete ""
End If
Next ' x
End With
End If
End Sub
 
Okay, my code compiles successfully now, but it doesn't delete the tag. When
I ShowTags, the empty tag is still there.

Any other ideas?
 
This work for you?

Sub Delete_Empty_Tag()
Dim x As Long
Dim oTag As Tags

Set oTag = ActiveWindow.View.Slide.Tags

With oTag
For x = 1 To .Count
If o.Name(x) = "" And .Value(x) = "" Then .Delete (x)
Next x
End With

End Sub


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
Try this instead:

Sub Delete_Empty_Tag()

Dim x As Long
Dim oSl As Slide

Set oSl = ActiveWindow.View.Slide
With oSl.Tags
' if you step forward through the range,
' deleting Tag 1 makes (formerly) Tag 2 --> Tag 1
For x = .Count To 1 Step -1
' This will also delete tags with spaces
' for values; if you don't want that
' remove the Trim statement
If Trim(.Value(x)) = "" Then
Debug.Print .Name(x)
.Delete (.Name(x))
End If
Next

End With
End Sub
 
Nope, Run-time error '424': Object required [referring to: If o.Name(x) = ""
And .Value(x) = "" Then .Delete (x) ]
 
This compiles and runs for me but does not delete the tag. When I run
ShowTags, the empty tag is still there.
 
This compiles and runs for me but does not delete the tag. When I run
ShowTags, the empty tag is still there.

Sounds like you've got tags with blank names as well.
Third try's charmed, maybe?

Sub Delete_Empty_Tag()
Dim x As Long
Dim oSl As Slide

Set oSl = ActiveWindow.View.Slide
With oSl.Tags
' if you step forward through the range,
' deleting Tag 1 makes (formerly) Tag 2 --> Tag 1
For x = .Count To 1 Step -1
' This will also delete tags with spaces
' for values; if you don't want that
' remove the Trim statement
If Trim(.Value(x)) = "" Then
Debug.Print .Name(x)
.Delete (.Name(x))
End If
Next
For x = .Count To 1 Step -1
' now go back and pick up the ones with blank names
If Trim(.Name(x)) = "" Then
.Delete (.Name(x))
End If
Next

End With
End Sub
 
No, same result. Thank you for the suggestions. I've just replaced the
slides and copied the content to the new slides. It seems that PowerPoint is
not able to target a tag for deletion if the tag's name or value property (or
both) is blank.
 
No, same result. Thank you for the suggestions. I've just replaced the
slides and copied the content to the new slides. It seems that PowerPoint is
not able to target a tag for deletion if the tag's name or value property (or
both) is blank.

I was able to make it work with spaces, but I suspect you're right ... totally
blank tags are probably not allowed, but got created anyhow. Somehow.
 
Back
Top