PDA

View Full Version : Macro to amend own code



Asterix
02-27-2008, 10:26 AM
I've broken a golden rule (well used to be golden when I used to code) and embedded some default text (i.e. data) as a variable assignment in my code.

The code sets up and sends an email and the variable in question is "body_text". What is assigned to body_text is a default message to go out on many emails that can be modified by the user.

What I'd like to do is, having recognised that the default body_text has changed, then offer the user who changed it the chance to replace the default text with the new, amended, text.

Do I need to remove the hard-coded default text from the code to do this (I realise it's probably advisable, but doing that alone would take me into uncharted waters)?

How do I update the default text, whether it's held in the original macro or separate to it?

Norie
02-27-2008, 10:39 AM
Why don't you store the default text somewhere?

Could be on a hidden worksheet.

Could be in a text file.

Then just alter the existing code to set body_text from wherever you've stored the default.

Note it is possible to use code to write code but it's not really advisable.

The main reason for that is that you'll have to change the user's security settings.

Bob Phillips
02-27-2008, 10:40 AM
I think I get half the story, but not all of it.

Presumably, you had a variable and hard-coded a value to it. How do you then that the default has changed, why can't you just assign that to the variable?

mikerickson
02-27-2008, 12:47 PM
Custom Document Properties sounds like a good place to stash the default message.

Asterix
02-27-2008, 02:04 PM
I think I get half the story, but not all of it.

Presumably, you had a variable and hard-coded a value to it. How do you then that the default has changed, why can't you just assign that to the variable?

...because the issue occurs once the macro stops and is restarted later (it'll revert to the hardcoded value).:think:

Bob Phillips
02-27-2008, 05:04 PM
The I would use an Excel name to store the value, and hide the name.