VBA Dragging a shape with Macro assigned to it...

hakanfa

New Member
Joined
Mar 25, 2020
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I have the following problem - Working with a project where I generate pictures and the pictures (Shapes) are assigned a macro that deletes the picture when clicked on a certain place on the picture. This works well - but when assigning a macro to the picture - the ability to move the picture by dragging is gone. Is there a way to restore it?

All possible ideas very welcome!


Best regards,
Hakan
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
as in because you click the picture, it deletes, or that the drag event does not work any more
 
Upvote 0
as in because you click the picture, it deletes, or that the drag event does not work any more
Hi,
the click-to-delete works fine - that is basically a if..then .else thing, but what I need is the ability to activate drag-drop if the user click on a position that will not delete the picture. This can be easily simulated by adding a shape - assign a random macro with like this:
Sub DemoClick()
Dim CallerShape As Shape: Set CallerShape = ActiveSheet.Shapes(Application.Caller)
If CallerShape.Fill.ForeColor.RGB = RGB(0, 0, 0) Then
MsgBox "Hello"
End If
End Sub

If the shape is black - you get a message "Hello" if not - nothing happens.. if the shape is not black I want to drag it to another position - that is not possible as there is a macro assigned the drag-drop is not activated on mouse-click. I know - the right click will do it but I would like to activate such possibility that click-and-hold would activate the drag-drop feature.

Br
Hakan
 
Upvote 0
Is this what you want ?
VBA Code:
Sub DemoClick()
    Dim CallerShape As Shape: Set CallerShape = ActiveSheet.Shapes(Application.Caller)
        If CallerShape.Fill.ForeColor.RGB = RGB(0, 0, 0) Then
        MsgBox "Hello"
    Else
        CallerShape.Select
    End If
End Sub
 
Upvote 0
Is this what you want ?
VBA Code:
Sub DemoClick()
    Dim CallerShape As Shape: Set CallerShape = ActiveSheet.Shapes(Application.Caller)
        If CallerShape.Fill.ForeColor.RGB = RGB(0, 0, 0) Then
        MsgBox "Hello"
    Else
        CallerShape.Select
    End If
End Sub
Gosh.. how did I miss that.. Jaafar, you seem to have a solution for all problems :)
Thank you for helping me out!

-HAkan
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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