+ Reply to Thread
Results 1 to 8 of 8

Called Code fails to run when assigned to button

  1. #1
    Registered User
    Join Date
    09-26-2024
    Location
    Nottingham
    MS-Off Ver
    Excel MS365 V2408
    Posts
    20

    Called Code fails to run when assigned to button

    In the attached workbook I have the following code:

    Please Login or Register  to view this content.
    This, in turn, is called in this code:
    Please Login or Register  to view this content.
    If I run this code manually, it runs perfectly, saves the worksheet as PDF, attached to an email and replaces forumals with existing data.
    However, I have a picture in cell A1, and I have assigned Email_PDF to this. All of the code runs EXCEPT for DeleteSomeFormulas

    stackoverflow.com/questions/79023420/code-doesnt-run-all-elements-when-applied-to-button-does-when-run-manually
    Attached Files Attached Files
    Last edited by DarrylBurge2; 09-26-2024 at 05:55 AM. Reason: Workbook Attached, Adding Cross-Post details

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,235

    Re: Called Code fails to run when assigned to button

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.
    For new members: you will not be able to post a full URL, so remove the https://www. section and add one or two breaks to the rest of the address. A Moderator or Admin will then fix the link for you.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As you are new here, I shall do it for you this time: https://stackoverflow.com/questions/...n-run-manually)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,968

    Re: Called Code fails to run when assigned to button

    Change the code to:

    Please Login or Register  to view this content.
    then call it using:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    09-26-2024
    Location
    Nottingham
    MS-Off Ver
    Excel MS365 V2408
    Posts
    20

    Re: Called Code fails to run when assigned to button

    then call it using:

    Please Login or Register  to view this content.
    When I change the call I get a
    "Compile Error:
    Expected: End of Statement"

  5. #5
    Registered User
    Join Date
    09-26-2024
    Location
    Nottingham
    MS-Off Ver
    Excel MS365 V2408
    Posts
    20

    Re: Called Code fails to run when assigned to button

    Line changed to
    Please Login or Register  to view this content.
    Is that the correct method, as it seems to do what it is supposed to with this change.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,968

    Re: Called Code fails to run when assigned to button

    You should not need to use Call. The original code I posted works.

  7. #7
    Registered User
    Join Date
    09-26-2024
    Location
    Nottingham
    MS-Off Ver
    Excel MS365 V2408
    Posts
    20

    Re: Called Code fails to run when assigned to button

    My Apologies, i assumed "Call it using" meant use "Call".

    It does work, thank you very much

  8. #8
    Registered User
    Join Date
    09-26-2024
    Location
    Nottingham
    MS-Off Ver
    Excel MS365 V2408
    Posts
    20

    Re: Called Code fails to run when assigned to button

    Quote Originally Posted by romperstomper View Post
    The original code I posted works.
    Hi Romper, further testing and the formulas are being stripped out when a new worksheet is being created.

    the only time DeleteSomeFormuals is being used is when Email_PDF is run.


    Nope, Apologies, I was running a legacy version.
    Last edited by DarrylBurge2; 09-26-2024 at 10:32 AM.

+ 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] Clicking on a button linked to VBA code fails to execute
    By jeriss in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-19-2023, 08:04 AM
  2. Edit code to refresh pivot table assigned to command button?
    By expeo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-19-2018, 12:37 PM
  3. [SOLVED] Why does code called from a macro button to write data to an excel table work correctly, b
    By mgeoyoung in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2017, 08:57 PM
  4. Macro assigned to button does not stay assigned
    By tuscan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2017, 02:22 AM
  5. [SOLVED] Userform code fails when the userform is called from a custom ribbon button
    By klonbeck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 03:00 PM
  6. macro fails to function correctly when called from button form control
    By sarails in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-22-2011, 01:39 AM

Tags for this Thread

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