-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenameShapesWithText
38 lines (35 loc) · 1.52 KB
/
RenameShapesWithText
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Sub RenameShapesWithText()
Dim sld As Slide
Dim shp As Shape
Dim shpText As String
' Loop through each slide in the presentation
For Each sld In ActivePresentation.Slides
' Loop through each shape in the slide
For Each shp In sld.Shapes
' Check if the shape has a text frame and contains text
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shpText = shp.TextFrame.TextRange.Text
' Use the text to rename the shape
' Truncate the text to 255 characters if it is too long
If Len(shpText) > 255 Then
shpText = Left(shpText, 255)
End If
' Replace invalid characters with underscores
shpText = Replace(shpText, ":", "_")
shpText = Replace(shpText, "\", "_")
shpText = Replace(shpText, "/", "_")
shpText = Replace(shpText, "*", "_")
shpText = Replace(shpText, "?", "_")
shpText = Replace(shpText, """", "_")
shpText = Replace(shpText, "<", "_")
shpText = Replace(shpText, ">", "_")
shpText = Replace(shpText, "|", "_")
' Rename the shape
shp.Name = shpText
End If
End If
Next shp
Next sld
MsgBox "Shapes renamed successfully!", vbInformation
End Sub