+ Reply to Thread
Results 1 to 6 of 6

VBA code to modify VBA code

  1. #1
    Registered User
    Join Date
    10-13-2011
    Location
    Jozi, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    93

    Question VBA code to modify VBA code

    Hello all,

    I would like to be able to use code to modify code, specifically a constant held in my macro. e.g; if I enter a name as a parameter "Ms Scarlet" i would like the current value held in the constant to be updated for future use:

    From:
    Please Login or Register  to view this content.
    To:
    Please Login or Register  to view this content.
    The change must be saved, so tha the next time the add-in is run, the new value is still relevant.

    Again, any assistance s appreciated.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA code to modify VBA code

    Why complicate it?
    If you want to change something then by definition it's not a constant!
    Why not just hold your variables on a dedicated sheet, protected and hidden if necessary.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    10-13-2011
    Location
    Jozi, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    93

    Re: VBA code to modify VBA code

    Thanks, I asked that question in another thread, but i see no spreadsheet available to store my data in my add-in.

    The value is constant until such time I choose to change it.

    I have a pop up form that asks which sales rep and which customer I am running a report for, once I am done with all sales rep A's reports, I start with the next rep. I would like my pop up form to remember the name of the sales rep since I last ran the macro.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA code to modify VBA code

    The value is constant until such time I choose to change it.
    I think you've got the wrong idea about constants, the point is you don't change them - otherwise they wouldn't be constant

    Why can't you do as Richard suggests and store the data on a sheet? - Writing code with code is hacky, it requires users to lower their security settings and can be blocked by antivirus software.

  5. #5
    Registered User
    Join Date
    10-13-2011
    Location
    Jozi, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    93

    Re: VBA code to modify VBA code

    I did not know this
    it requires users to lower their security settings and can be blocked by antivirus software.
    Thanks, I will research more on storing the data in a worksheet.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA code to modify VBA code

    Holding variables (as well as constants) on a dedicated sheet is an exceedingly common approach. I use it all the time.

+ 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