Consulting

Results 1 to 2 of 2

Thread: 1004 error on delete picture on mouseover VBA

  1. #1

    [FIXED] 1004 error on delete picture on mouseover VBA

    I've got a simple code I use to delete a created picture before which was triggered by mouseover. The following code uses the same method as Show_MouseOver but it's deleting the passed object - lets name it Hide_MouseOver.
    PublicFunction Reset(Friendlyname AsString)
    If DoOnce Then
    
        Application.ScreenUpdating =False
        Unprotect
        DoOnce =False
    
        Dim URL AsString
        Dim Pict
        Dim drOBJ
    
        Set drOBJ = ActiveSheet.DrawingObjects
        ForEach Pict In drOBJ
            If Pict.Name = Friendlyname Then
                Pict.Select
                Pict.Delete
            EndIf
        Next
        Protect
        Application.ScreenUpdating =True
    EndIf
    EndFunction
    
    It's working easy and good. However the problem I discovered stays like that:
    1) I have multiple Show/Hide icons triggering creation and deletion of different pictures from the local disk
    2) If user triggers Show of 1 picture and ALSO TRIGGERS Show of 2 picture WITHOUT triggering Hide of 1 picture, The HIDE of picture 1 will not work after that and trigger 1004 error - Unable to get the name property of picture class.

    I can't really find out what is the problem with that because each of my hide icons has separate code to hide specific picture and since the name of picture is set when it's shown I don't understand why Excel return an error on it. F.E. the hide object:
    PrivateSub RegBubbles_hide_MouseMove(ByVal Button AsInteger,ByVal Shift AsInteger,ByVal X AsSingle,ByVal Y AsSingle)
        Reset ("RegBubbles")
    EndSub
    Last edited by sickless299; 11-15-2018 at 11:25 AM.

  2. #2
    Nvm. Solved by working with ActiveSheet.Shapes instead of DrawingObjects.

Posting Permissions

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