I wonder if there is a way to store values in some kind of global variables
for macros between runs as long as the document remains open.
I have seen how to create serial numbers and stuff by storing numbers to
text files. But I wonder if there is a smarter way as long as I have my
document open. In essence I have a macro making multiple runs on the same
document and it should preferably behave a little different depending on how
the run of the previous run ended up.
Regards
Per
old man - 13 Jul 2007 01:06 GMT
Hi,
The 'old' way was to use a static variable in the procedure. Values assigned
to a static variable keep their values until the document is closed.
sub addit()
static i1 as integer
' i1 will keep its value (or new value) every time addit is run
i1 = i1 + 1
..
exit sub
The new way to maintain a value is to use a variable object (This is
available as of Word 2003 - I am not sure it was available earlier).
ActiveDocument.Variables.Add Name:="i1", Value:="1"
to later check the contents of a variable (which is a part of the variables
collection) use:
ActiveDocument.Variables("i1").Value
old man
> I wonder if there is a way to store values in some kind of global variables
> for macros between runs as long as the document remains open.
[quoted text clipped - 7 lines]
> Regards
> Per
periodic - 13 Jul 2007 01:26 GMT
Ahh thanks, thats just what I was looking for.
I am using word 2003 now so it worked just fine
Russ - 13 Jul 2007 01:28 GMT
Storing Values When a Macro Ends
http://snipurl.com/swu3
Rerunning code over the same document is tricky. I usually had to have as
part of the code at the beginning to delete bookmarks, headings and footers,
white space, etc., if my code was going to create that stuff again.
Otherwise, those things just grow and grow or complain about being in
existence already.
> I wonder if there is a way to store values in some kind of global variables
> for macros between runs as long as the document remains open.
[quoted text clipped - 7 lines]
> Regards
> Per

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID