#1
|
|||
|
|||
All Shapes on slide
I have been learning a lot about VBA lately but am stumped on this one. I would like a loop that goes through the current slide of my presentation and grabs all the shape names. I know how to get all the names in a variable but cant get the loop started to extract each shapes name.
Any help is appreciated. |
#2
|
|||
|
|||
Where do you want the shape names to end up?
Message Box? Array? Immediate pane? Print on slide? In a text file? Somewhere else? Example Sub getShapeNames() Dim oshp As Shape Dim osld As Slide Dim strReport As String strReport = "Shapes On Slide" & vbCrLf & "===========" & vbCrLf & vbCrLf On Error Resume Next Set osld = ActiveWindow.View.Slide If Not osld Is Nothing Then ' check slide in view For Each oshp In osld.Shapes strReport = strReport & oshp.Name & vbCrLf Next oshp If strReport = "" Then strReport = "No shapes!" MsgBox strReport End If End Sub |
#3
|
|||
|
|||
Sweet Thanks John,
Sorry for not being really specific this time but I am working on learning VBA so I just needed the start on this code. I'm going to play around with it and see what I can do. Thank you again. |
#4
|
|||
|
|||
That's a good way to learn.
Since it's not at all obvious here's how to put the report in a file on the Desktop Sub getShapeNames_toFile() Dim oshp As Shape Dim osld As Slide Dim strReport As String Dim filenum As Integer Dim strSavePath As String filenum = FreeFile ' next available # usually but not always 1 strSavePath = Environ("USERPROFILE") & "\Desktop\report.txt" strReport = "Shapes On Slide" & vbCrLf & "===========" & vbCrLf & vbCrLf On Error Resume Next Set osld = ActiveWindow.View.Slide If Not osld Is Nothing Then ' check slide in view For Each oshp In osld.Shapes strReport = strReport & oshp.Name & vbCrLf Next oshp If strReport = "" Then strReport = "No shapes!" Open strSavePath For Output As filenum Print #filenum, strReport Close filenum End If End Sub |
#5
|
|||
|
|||
Sorry to ask again but is there a way to the msgbox code above without having the presentation open I am trying the following.
Sub getShapeNames() Dim oshp As Shape Dim Mylibrary As Presentation Dim osld As Slide Dim strReport As String strReport = "Shapes On Slide" & vbCrLf & "===========" & vbCrLf & vbCrLf On Error Resume Next Set Mylibrary = Presentations.Open(Environ("USERPROFILE") & "\My Documents\CustomShapes.ppt", WithWindow:=False) For Each oshp In Mylibrary.Shapes strReport = strReport & oshp.Name & vbCrLf Next oshp msgbox strReport |
#6
|
|||
|
|||
The only way to do this without opening would be to query the XML. This is not a simple thing to do! You would need to Google Microsoft XML DOM or OpenXML SDK.
Be warned though this is an order of magnitude harder than what you are doing. Is there a problem opening a windowless copy (and closing it when you are done) It should be quite transparent. |
#7
|
|||
|
|||
Quote:
|
#8
|
|||
|
|||
I tired my above code again and I still cant get it to work as a windowless copy. Is there different code I should use?
|
#9
|
|||
|
|||
Quote:
Just had to do a little bit of research here is the solution. Code:
Sub shapelist() Dim curlibrary As Presentation Dim oshp As Shape Dim AllShapeMsg As String Dim curosld As Slide Set curlibrary = Presentations.Open(Environ("USERPROFILE") & "\My Documents\CustomShapes.ppt", WithWindow:=False) Set curosld = curlibrary.Slides(1) For Each oshp In curosld.Shapes AllShapeMsg = AllShapeMsg & oshp.Name & vbCrLf Next oshp curlibrary.Close MsgBox AllShapeMsg End Sub |
#10
|
|||
|
|||
Well done!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Copy & Paste Shapes & Motion Paths from 1 Slide Size to Another | buckaroobanzai | PowerPoint | 1 | 06-08-2012 05:32 AM |
Where did map shapes go? | SueK | PowerPoint | 1 | 01-20-2011 04:30 AM |
Find and add new Shapes | bonani | PowerPoint | 1 | 11-26-2009 06:21 PM |
Shapes Will Not Display | JoeTx | Visio | 0 | 03-13-2008 09:01 AM |
My Shapes some appear some don't | Jean-Paul | Visio | 0 | 03-01-2006 01:38 AM |