msoPropertyTypeString too short

M

Martin

I'm writing a series of macros in VBA for Word. I need to set aside some
text so that a subsequent macro can look at it. I want to store it in a
custom document property, but msoPropertyTypeString is limited to 255
characters, and the text I want to store is sometimes longer than that. Is
there any other custom property type that I can use, or any other way that I
can store a bit of text outside of a running macro?

Thanks for your help.

Martin
 
K

Klaus Linke

Hi Martin,

Depends on what you want to do.

If you need the string variable again running the same macro at a later time, you could define it as Static.
Or if you want it available in all macros (until you quit Word), you could define it as Public at the top of the module.

If you want the string saved along with the doc (or template), you can use document variables (up to 64 kB in length):
ActiveDocument.Variables.Add Name:="SomeName", Value:="SomeString"

Or you might use some external (Unicode) text file to store strings.

Greetings,
Klaus
 
M

Martin

Thank you, Klaus! That is definitely among the very best answers that I have
ever received to any question. I used ActiveDocument.Variables and it worked
perfectly on the first try. I can see that defining it as Public would be
more elegant, and merging to two macros and then using a Static would be
even more elegant, but I will have to learn a little about those things
first. In the mean time, my macro works, thanks you your help!

Martin

Hi Martin,

Depends on what you want to do.

If you need the string variable again running the same macro at a later
time, you could define it as Static.
Or if you want it available in all macros (until you quit Word), you could
define it as Public at the top of the module.

If you want the string saved along with the doc (or template), you can use
document variables (up to 64 kB in length):
ActiveDocument.Variables.Add Name:="SomeName", Value:="SomeString"

Or you might use some external (Unicode) text file to store strings.

Greetings,
Klaus
 
K

Klaus Linke

Glad it worked well! I don't have much experience with document variables.
One nice thing about them is that you can insert them in the document using DocVariable fields:
{ DocVariable SomeName }

Greetings,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top