I've looked at other forum posts on dynamically named variables, but I can't figure out from them how to do what I want to do, so -- new post.
I have a macro (call it "make-changes" for simplicity) that takes note of certain characteristics of the front window, stores that info in global variables, and then resizes and otherwise alters the window so that I can do some tasks more conveniently. I have another macro ("revert-changes") that undoes those alterations, using the previously set global variables to restore the initial values.
(To be more specific, in case it matters somehow: I do a lot of complicated text editing in MS Word using Track Changes. I'm usually working in Draft view with windows narrow enough to see several at a time across my two monitors; but when I want to insert a comment, it's easier for me to do so in Print view with the window wide enough to see the entire text plus the comment area, and I also don't want tracked changes showing for this. So I have a first macro that notes the current window frame, whether Track Changes is active, whether tracked changes are showing, the current zoom and horizontal scroll percentages, and what the view type is; and then it enlarges the window, changes all the view options, and inserts a comment ready for me to type into. When I'm finished composing the comment I can trigger the second macro to restore the window to whatever size, position, view, etc. it was originally in. But these details probably don't matter; the principle is the thing.)
I can't use local variables for this, because "make-changes" and "revert-changes" are two different macros. I can't combine them into one macro that either makes or reverts changes depending on circumstances, for complex reasons having to do with my workflow.
My problem is that if I run the "make-changes" macro in one window, and then want to run it again in another window before I've run "revert-changes" on the first window, the second call to "make-changes" overwrites the global variables. So, since I can't associate the variables holding the initial values with a specific instance of the macro, I want to find a way to associate them with their window.
So I'm wondering if it's possible to create global variables whose name includes the name of the window they pertain to. When "make-changes" is triggered when the front window is named Main Document, it would set global variables named Main Document Frame, Main Document View Type, Main Document Changes Visible, and so on; when it's called when the window is named Bibliography, it would set global variables named Bibliography Frame, Bibliography View Type, Bibliography Changes Visible, and so on. And then when "revert-changes" is triggered, it would use the global variables containing the name of the front window.
For extra fun, I usually have two or three windows open on the same document, which means that the front window name may well look like "Main Document.docx - 1" or "Main Document.docx - 2". Is the dash going to cause problems if it's part of a variable name?
Is it possible to do this? Or is what I've got as good as it gets? (And it's pretty damn good; every time I run these macros, which is twenty to sixty times a day, I bless Peter's name ) Thanks for any suggestions!