0

I am currently making a macro for MS Office Word 2007. The macro requires use of variables that I want to store in the ActiveDocument.Variables list. I want to store and use arrays from this list, but I am encountering problems. Is there a way to store arrays as an active document variable?

Thanks.

4
  • From a quick look it doesn't seem possible. Why do you want to store it in the Variables collection? Maybe share your code to give us an idea of what you want to do. Commented May 16, 2018 at 20:51
  • @BigBen I am trying to make a macro that uses the same variable for each document when multiple documents are open and holds different values. An example would be if I wanted to store maybe like the top ten words in a document in an array with multiple documents open. Each need their own unique items stored in the same variable. Currently, my program is just using the same values regardless of the current active document. I am unsure how to differentiate the documents. Commented May 16, 2018 at 20:57
  • Please share the code you've tried, along with the specific error you're getting. Commented May 16, 2018 at 21:03
  • <<Currently, my program is just using the same values regardless of the current active document. I am unsure how to differentiate the documents.>> Possible approaches include using an array of a user-defined data Type objects, or defining a Class whose objects are held in an array or a Collection. Commented May 17, 2018 at 17:04

1 Answer 1

2

A Document Variable can store only a string. A Document Variable is not a variable in the programming sense of the term. It's a storage space in the document structure - thus, it can only store a string of characters.

You could store the information as a character-delimited string in the document Variable. The Split and Join functions can turn such a string into an array or, respectively, turn an array into such a string. So conversion back-and-forth would be relatively simple.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.