+ Reply to Thread
Results 1 to 7 of 7

[Solved]On Click command button function

  1. #1
    Registered User
    Join Date
    12-02-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Question [Solved]On Click command button function

    I'm trying to create a macro for a command button that when clicked, will get the job number from that row and look for a file for that job. If it does not exist I want it to copy from a template and save with a new name, otherwise just open the file.

    However, I cannot seem to work out how to get hold of the information for the command button that calls the macro. This is what I have so far:

    ShapeExists, checks if a button on that row exists, if not it creates one if a cell in that row has changed.

    JobButton is what I am having problems with.

    Please Login or Register  to view this content.
    As you can see I am currently trying ActiveSheet.Shapes(Application.Caller).Select, this is causing a "Run-time error '13': Type mismatch".

    Any help would be much appreciated, thank you!
    Last edited by Aitchy; 12-02-2010 at 03:13 PM.

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

    Re: On Click command button function

    In a test file your code works, until it tries to open template.

    Where in your code does the error occur?
    can you post example file to demonstrate the problem
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    12-02-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: On Click command button function

    Job Tracking is the main file, and I'm trying to test the command buttons in column O.

    When I click the "Open Job" button in the Job Tracking file attached above, I get an error 400 message.

    So stepping through the JobButton method I get a Run-time error'13': Type mismatch on :

    ActiveSheet.Shapes(Application.Caller).Select

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

    Re: On Click command button function

    The first issue was that the code you posted was not the code used in your example files.
    The use of the ME object within a sheet object will refer to the sheet not the button that was just pressed.

    This assigns the shape to a object variable for use within the code.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-02-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: On Click command button function

    Ah yes sorry, I have changed my attachment.

    Thanks for the code above, but I still get the same error 400 when I click the button and run-time error 13 when stepping through the method.

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

    Re: On Click command button function

    I do not get a 400 error. I do get a 1004 error if the current directory is not the one with the template file in it.

    Adding the exact folder would help.
    Please Login or Register  to view this content.
    You can no simply step into and through the macro as the Application.Caller value will cause an error.
    You can trap for that

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-02-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: On Click command button function

    That was the problem, thank you so much for the help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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