Solved

Excel VBA - deleting all objects except graphics

Posted on 2011-09-19
3
375 Views
Last Modified: 2012-06-27
I have a worksheet with buttons and pictures.  The code I tried (below) deletes all shapes but I want to ONLY delete buttons (NOT the pictures).

How can I delete only buttons?

            iCount = ActiveSheet.Shapes.Count
            For i = iCount To 1 Step -1
                ActiveSheet.Shapes(i).Delete
            Next i

0
Comment
Question by:AndresHernando
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 350 total points
ID: 36558610
Which kind of buttons are they? Forms or ActiveX?
If Forms:
 iCount = ActiveSheet.Buttons.Count
            For i = iCount To 1 Step -1
                ActiveSheet.Buttons(i).Delete
            Next i

Open in new window

0
 
LVL 15

Assisted Solution

by:Haris Djulic
Haris Djulic earned 150 total points
ID: 36558639
if they are all named CommandButton you can use this

        iCount = ActiveSheet.Shapes.Count
            For i = iCount To 1 Step -1
if Mid(ActiveSheet.Shapes(i).Name, 1, 7) <> "Command" then
                ActiveSheet.Shapes(i).Delete
end if

            Next i
0
 

Author Comment

by:AndresHernando
ID: 36559286
rorya, thanks for your help (again).  Works perfectly.

Sam, thanks for your input.  Your solution adds value.  I can see where I can use this. Thanks!

I'll split points 350/150.  I hope that's OK.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.Range Set 25 76
Quarter Increment Clock 2 15
Excel Conditional Statements 11 35
Office 2016 without internet 6 36
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question