How do you make a shape selected in VBA visible?

QuantBurner

New Member
Joined
Jan 29, 2011
Messages
42
Hi,
I have a macro that loops through all the shapes in an area. It selects the shape so the user can see what's been selected and then asks the user if he wants to keep it or not. This all works fine if I step through the code or execute from within VBA. However, if I run the macro via a button, nothing appears to be selected. So, how to I make the selected shape visible to the user?

Thanks!

Here's my code:

For Each shpShape In Activesheet.Shapes
If shpShape.Top >= dblTop And _
shpShape.Left >= dblLeft And _
shpShape.Left + shpShape.Width <= dblRight And _
shpShape.Top + shpShape.Height <= dblBottom Then
shpShape.Select
strKeepIt = MsgBox("Keep this text box?", vbQuestion + vbYesNo)
If strKeepIt = 7 Then shpShape.Delete
End If
Next shpShape
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Do you have the line
Code:
Application.ScreenUpdating = False
In your code before the loop below occurs?
 
Upvote 0
Just to clarify: I can't see what's been selected if I click the run button in the VBA editor. It's only when I step through the code that I can see what's been selected. Seems like I need something like DoEvents or SetFocus?
 
Upvote 0
Problem Solved!
Even though I never turned screenupdating off, I got my macro to work by turning screenupdatingon everytime I wanted to show what was selected.
Cheers
 
Upvote 0
Sorry to jump on an old thread, but this is exactly what I'm after. Except I'm writing for a client in Excel 2003 and it doesnt appear to work - wherever I put it!!

This is the code i have:

Application.ScreenUpdating = True
For Each n In ActiveSheet.Shapes
Application.ScreenUpdating = True

n.Select

Application.ScreenUpdating = True


response = MsgBox(n.Name & vbCrLf & "Would you like to rename this control?", vbYesNo)

If response = vbYes Then

newname = InputBox("Enter new control name")
If newname <> "" Then
n.Name = newname
Else
MsgBox "Not suitable"
End If


End If
If MsgBox("Bail?", vbYesNo) = vbYes Then Exit Sub
Next n


Any thoughts?

Cheers.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top