+ Reply to Thread
Results 1 to 5 of 5

VBA Macro Works Fine Until Applied to ActiveX Button - Solution Needed

  1. #1
    Registered User
    Join Date
    01-29-2018
    Location
    Toronto
    MS-Off Ver
    MS Office 2013
    Posts
    17

    VBA Macro Works Fine Until Applied to ActiveX Button - Solution Needed

    Essentially I have constructed a macro to update 2 pivot tables (and associated charts, on "Summary.." sheets) using data that will be periodically updated on "Activity" sheet. The macro works perfectly fine when run using the standard VBA editor Run function, also when I assign the macro to a Quick Access Toolbar at the top left of Excel. However, when I assign the macro to a command button (ActiveX) on the "Summary" sheets I suddenly receive error 1004 (See screenshots below), while the macro works perfectly fine in all other methods.
    Could somebody find a solution that would allow the macro to run via the ease of clicking a simple command button (preferably a button on each of the "Summary" sheets that runs the exact same function)? Obviously, I wouldn't specifically require ActiveX Controls if you can advise an alternative. Attached is a sample example of the workbook!
    Thank you in advance!

    Please Login or Register  to view this content.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: VBA Macro Works Fine Until Applied to ActiveX Button - Solution Needed

    Hi Migos,

    This sounds like a "where your code is located" type of problem. Read about Standard Modules vs other types of Modules at:

    https://msdn.microsoft.com/en-us/lib...ffice.12).aspx

    It seems like your code is behind the ActiveX control so when the code is asked to select a Column, there is no column object in the control.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    01-29-2018
    Location
    Toronto
    MS-Off Ver
    MS Office 2013
    Posts
    17

    Re: VBA Macro Works Fine Until Applied to ActiveX Button - Solution Needed

    Is there any way I could simply keep the macro within the workbook, and any time the workbook is opened (or saved, whatever is possible), the macro is simply run?

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: VBA Macro Works Fine Until Applied to ActiveX Button - Solution Needed

    Sure,

    Make sure the macro is in a Standard Module so it isn't limited to a single sheet or userform and then call the macro from an Event Macro behind the ThisWorkbook Module. You would call the Standard Module code when the workbook event is an Open or BeforeClose.

    It is a pretty common problem for people not understanding the Scope of the code. Read also:

    http://www.cpearson.com/Excel/Scope.aspx

  5. #5
    Registered User
    Join Date
    01-29-2018
    Location
    Toronto
    MS-Off Ver
    MS Office 2013
    Posts
    17

    Re: VBA Macro Works Fine Until Applied to ActiveX Button - Solution Needed

    Thank you so much! I sorted it out!

+ 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. Single step works fine but command button has errors
    By CptCrunch51 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2017, 01:07 PM
  2. ActiveX Command Button combined with ActiveX List Boxes – VBA Code Needed
    By Stlcards13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-26-2017, 02:56 PM
  3. Disable Insert button code works fine, but some times throws Run-Time error '5'
    By challasl in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-18-2016, 05:41 AM
  4. Application.Run Macro Works Fine For Me, Not For Another
    By EnergyHOU in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2016, 10:43 AM
  5. [SOLVED] Help with modifying VBA Macro - Works fine but needs fine tuning !
    By stefan27 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2015, 10:27 AM
  6. Vlookup works fine, but not in Macro
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2010, 12:54 PM
  7. Macro works fine... until I save it
    By hoffey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-23-2009, 04:34 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