Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Remebering values from different runs in a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
periodic - 13 Jul 2007 00:32 GMT
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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.