+ Reply to Thread
Results 1 to 7 of 7

VBA - Grouping Shapes & Deleting Them

  1. #1
    Registered User
    Join Date
    11-03-2020
    Location
    Colorado
    MS-Off Ver
    Office 365
    Posts
    6

    VBA - Grouping Shapes & Deleting Them

    I already have a macro that will draw up to 36 shapes (combo of ovals and freeforms) all on a range I call "DrawRange". I am trying to add to this to group all the shapes so that a user can move/manipulate the drawing easily. And I would like to also be able to delete this shape, via VBA, in the event of a "re-draw" event initiated by a user.

    The code I have currently for the group is similar to delete so we'll just focus on that. Here is what I have:

    Please Login or Register  to view this content.
    This works... sometimes. However often enough I get an error "Application-Defined or Object Defined Error" listed on the "Not Intersect" line. I'm not sure what I'm being told in that error message nor how to go about fixing it. Any help is greatly appreciated.

    And for anyone interested, the delete routine is similar to above except after the Not Intersect line, I use "shp.delete".

    Thank you
    Last edited by CUCE; 11-03-2020 at 06:39 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA - Grouping Shapes & Deleting Them

    Why not group the shapes when you create them?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-03-2020
    Location
    Colorado
    MS-Off Ver
    Office 365
    Posts
    6

    Re: VBA - Grouping Shapes & Deleting Them

    Norie - The shapes come out of a vba routine unselected and there are a quite a bit of them. It would be inconvenient to manually select them all each time.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA - Grouping Shapes & Deleting Them

    Why would you manually select them?

    All you need to group shapes is an array with the names you want to group.

    So, in the code that creates the shapes note the name of each shape in array and at the end group them.

  5. #5
    Registered User
    Join Date
    11-03-2020
    Location
    Colorado
    MS-Off Ver
    Office 365
    Posts
    6

    Re: VBA - Grouping Shapes & Deleting Them

    Norie - Maybe the issue is not knowing how to name these shapes as I build them. This is part of the drawing code that builds the oval shapes. The rebar array is simply a table of x, y, width, height values.

    Please Login or Register  to view this content.
    When I run this, ALL the ovals come in with the same name "Rebar". And my efforts to group based on name only grabs the last one drawn. Is there a way to name them Rebar 1, Rebar 2, etc with what you see above?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA - Grouping Shapes & Deleting Them

    All you need to do is incorporate the loop variable i into the name.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-03-2020
    Location
    Colorado
    MS-Off Ver
    Office 365
    Posts
    6

    Re: VBA - Grouping Shapes & Deleting Them

    Norie. Thank you. This was the missing link I needed.

    And just for anyone who reads this later. I created another loop to grab any shape with "rebar" in its name. The code is below. Naturally, I'll place it in my drawing routine as recommended above. Thank you again!

    Please Login or Register  to view this content.
    Last edited by CUCE; 11-03-2020 at 06:49 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Grouping charts and shapes programatically
    By tonyd5 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2018, 03:38 AM
  2. [SOLVED] Shapes and Deleting Shapes
    By rob_h in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-24-2017, 10:07 AM
  3. VBA grouping shapes by position
    By bluphoto in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2014, 01:23 PM
  4. Need help with grouping shapes using an array
    By plucier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-13-2013, 12:22 AM
  5. checking if shapes exist and grouping them
    By gummi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-21-2008, 11:12 AM
  6. Grouping Shapes
    By LaraBee in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-14-2007, 03:55 PM
  7. Deleting Shapes
    By aftamath in forum Excel General
    Replies: 5
    Last Post: 11-04-2005, 08:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1