|
-
Aug 2nd, 2006, 05:08 PM
#1
Thread Starter
Junior Member
[RESOLVED] Excel: select mult. shapes if their names contain a string
Hi and thanks for reading my post!
I have [any] number of shapes in one sheet. They have names such as "BigShape 10", "BigShape 11", "MedShape 7", etc.
I need to select all shapes, whose name contain a certain string (for examle "gSh" from the example above).
Could anybody kindly help, please?
Many thanks in advance!!
Pavel
-
Aug 2nd, 2006, 05:24 PM
#2
Re: Excel: select mult. shapes if their names contain a string
Welcome to the Forums.
Are you needing this in Excel VBA or via VB 6 automation?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 3rd, 2006, 10:47 AM
#3
Thread Starter
Junior Member
Re: Excel: select mult. shapes if their names contain a string
Thanks for your reply. I am using VB 6.1 from Office XP.
-
Aug 3rd, 2006, 10:49 AM
#4
Re: Excel: select mult. shapes if their names contain a string
Moved.
-
Aug 3rd, 2006, 01:28 PM
#5
Re: Excel: select mult. shapes if their names contain a string
What type of shapes are they? All the same kind? How did you add them? From the Drawing toolbar, Controls toolbar, etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 3rd, 2006, 05:05 PM
#6
Thread Starter
Junior Member
Re: Excel: select mult. shapes if their names contain a string
They are all rectangles. I don't have the code with me at this moment, but I have written a macro that creates rectangles with appropriate size etc. then i have macro that changes selected shape according to its name. I just cannot figure out how to select several shapes (rectangles in my case) that have a certain string in their (custom) name.
-
Aug 4th, 2006, 05:41 AM
#7
Re: Excel: select mult. shapes if their names contain a string
VB Code:
Sub selectshapes()
Dim s As Shape, myarr(), n As Integer
ReDim myarr(Sheet4.shapes.Count)
For Each s In Sheet4.shapes
If Not InStr(s.Name, "Combo") = 0 Then
myarr(n) = s.Name
n = n + 1
End If
Next
ReDim Preserve myarr(n - 1)
Sheet4.shapes.Range(myarr).Select
End Sub
this works for comboboxes, so should wor for your rectangles
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 4th, 2006, 02:36 PM
#8
Thread Starter
Junior Member
Re: Excel: select mult. shapes if their names contain a string
This is it! Many, many thanks!!
I only had about 30 minutes to play with your code so far. It uses stuff I haven't use before, so I will read about it first. I also had to change sheet4 to ActiveSheet for some reason (renaming didn't work), but it already does what I needed so much. It selects the shapes with the string ("Combo" in your code). It seems like I will be using your code almost every day from now on. You really helped a lot! A lot!
All the best wishes!!
Pavel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|