+ Reply to Thread
Results 1 to 13 of 13

Assign a shape to macro excel 2007

  1. #1
    Registered User
    Join Date
    06-10-2015
    Location
    staunton,va
    MS-Off Ver
    2007
    Posts
    7

    Assign a shape to macro excel 2007

    Hi,
    I tried several ways as suggested on line to assign a shape to a macro. This can be done interactively, however; there are several hundred assignments to be made over several sheets.
    It would be super if I could nail the syntax to just assign one.
    Recording this action shows: selection.onaction = "Sheet26.rm221m" ' and that's all.
    Several attempts to code this give error message: run time error 438 object doesn't support this property or method
    A sub on the active sheet26 containing shape rm221 and macro rm221m
    Sheet26.Shapes("rm221").selection.onaction = "Sheet26.rm221m"
    Several alterations to the line above were tried, including adding the workbook in the assignment.

    How can I assign a macro to a shape in VBA 2007
    Thanks,
    Keith

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Assign a shape to macro excel 2007

    drop the selection part.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    06-10-2015
    Location
    staunton,va
    MS-Off Ver
    2007
    Posts
    7

    Re: Assign a shape to macro excel 2007

    Hi Andy,
    Thanks for the response. This also fails: runtime error 1004, application-defined or object-defined.
    sheet26 is the current-active ws containing macro rm212m and the object rm221. A separate amcro
    also on sheet26 tries to make the assignment listed; Sheet26.Shapes("rm221").onaction = "Sheet26.rm221m" .
    I also tried many variations of this as suggested on line w/o success.
    thanks,
    keith

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Assign a shape to macro excel 2007

    you need to post example file then as in my test it worked fine

  5. #5
    Registered User
    Join Date
    06-10-2015
    Location
    staunton,va
    MS-Off Ver
    2007
    Posts
    7

    Re: Assign a shape to macro excel 2007

    OK
    Private room(0 To 300) As Integer
    Sub asign_mac()
    Sheet26.Shapes("rm221").onaction = "Sheet26.rm221m"
    End Sub
    Sub rm221m()
    Range("i4").Value = Range("k13").Value
    Call Sheets("acf").update
    End Sub
    Sub update()
    Call mgrms.gacf("acf", room)
    End Sub

    note this is part of sheet26 = "acf"
    call grms.gacf("acf",room) is module that works and called by other procedures
    I can do this assignment interactively and it behaves.
    thanks,
    Keith

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Assign a shape to macro excel 2007

    doesn't really help us to help you.

    you need to attach example file that illustrates the problem

  7. #7
    Registered User
    Join Date
    06-10-2015
    Location
    staunton,va
    MS-Off Ver
    2007
    Posts
    7

    Re: Assign a shape to macro excel 2007

    Hmm,
    I'm not sure what you're seeking. the code listed is the sample. The xlsm is still small: 180kb. How do I attach it?
    thanks,
    Keith

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Assign a shape to macro excel 2007

    doesn't really help us to help you.

    you need to attach example file that illustrates the problemAttach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  9. #9
    Registered User
    Join Date
    06-10-2015
    Location
    staunton,va
    MS-Off Ver
    2007
    Posts
    7

    Re: Assign a shape to macro excel 2007

    Hi,
    I cut-paste the few lines of code into new wb, copied rm221 to it and it DOES WORK.
    This copied version bypassed module update and mgrms.gacf("acf", room). They also
    work but in a way not yet seen, all this re-direction is the root to the problem. I will
    take a little more time to better understand it, maybe the active sheet is lost and I need
    to replace the references to them.
    thanks,
    keith

  10. #10
    Registered User
    Join Date
    06-10-2015
    Location
    staunton,va
    MS-Off Ver
    2007
    Posts
    7

    Re: Assign a shape to macro excel 2007

    Hi Andy,
    Thanks for your patients. I do not see what's wrong. and attached redroof.xlsm
    Sheet5 ("addmac") will attach macro to shapes. Basic page with copy from Sheet26 ("acf")

    Sheet26 ("acf") sub assign_macro fails. I commented out 'call update' but same result.

    Sorry I do not see what's different B/W these two pages.

    thanks,
    keith
    Attached Files Attached Files

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Assign a shape to macro excel 2007

    You did not mention you shapes where grouped.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    06-10-2015
    Location
    staunton,va
    MS-Off Ver
    2007
    Posts
    7

    Re: Assign a shape to macro excel 2007

    Hi Andy,
    Thanks for your reply, got some vb insight to manipulating groups that'll be helpful in this project.
    Sheet5(addmac) was initiated in response to your earlier thread response requesting an example. In doing so I learned the syntax you listed did add a macro. This was already tried along with many variations to do same but ended in failure when used on Sheet26(acf) .
    Sheet5's code is in Sheet5 and same code exists in sheet26(acf) to add single macro assignment rm221m to rm221. Sheet5 started simple with one shape: "Rectangle 1" and the assign macro sub worked. I then copied group "Group 100" from Sheet26 to do same and it worked. I do not see why this is true.

    Why did you need to remove "Group 2" on Sheet5? The macro on Sheet5 makes the macro assignment to rm221 directly.

    The purpose of the macro in this case is real simple: if shape rm221 is selected (one click) then copy contents from one cell to another (date). I would have used cells but that's 2 clicks.
    On line searches I stumbled onto Application.Caller which will require only one macro to be used for all shapes by name. Seems like the way to do it. Any gotchas with this method.
    Thanks again for your patients and help,
    Keith

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Assign a shape to macro excel 2007

    I get error 1004 when trying to set the onaction of a grouped item. So I ungrouped, set onaction and then regrouped.

+ 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] Assign Macro from another Workbook to Shape
    By nicotob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2014, 05:47 PM
  2. Assign macro with parameter to shape based on shape location
    By bobo3127 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2014, 11:18 AM
  3. macro to assign cell to shape
    By jw01 in forum Excel General
    Replies: 1
    Last Post: 07-25-2011, 02:36 PM
  4. Assign Macro to shapes and use shape.name to define action
    By globalpontoon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2011, 03:19 AM
  5. Assign Macro to shapes and use shape....text to define action
    By globalpontoon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2011, 02:30 PM

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