Solved

Maximum length of  document variable using VBA in Word

Posted on 2013-11-18
2
1,394 Views
Last Modified: 2013-11-18
Working with VBA in Word, I have a long string, 1,899,391 characters long. I want to save it as a document variable. VBA objects and says my string is too long. I’ve tried VBA Help, the Internet, and EE, and nowhere can I find the maximum length possible for a document variable. If I knew that, I could chop my variable into shorter strings to save separately.
    Thanks for any suggestions. I can give further details on the problem if necessary.
     JRA in Priddis, Alberta
0
Comment
Question by:JohnRobinAllen
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 200 total points
ID: 39656564
This macro raises the error when l=65281, so I guess that the maximum length is 65280.
Sub DocVar()
Dim var As Variable
Dim l As Long

Set var = ActiveDocument.Variables.Add("myvar", "A")
Do Until False
    l = l + 1
    var.Value = String(l, "A")
Loop

End Sub

Open in new window

1
 

Author Closing Comment

by:JohnRobinAllen
ID: 39656597
That took about five minutes between time of submission of the question and the answer. Thanks for that help.
     In the meantime I found I made a stupid mistake that created the long string, so for the moment I no longer need that figure. However, in time as this program develops, my string to save will definitely get longer, so that I need that figure for when that happens.
     I'll check the length of the string each time I need to save it, and if the string exceeds 65,280, I'll chop it into two shorter strings, each half the length of the string to save.
     Thanks again to the oracle from London (UK, of course, not London, Ontario).
     John Robin (Allen)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Modify table cell in winword via automation 3 44
MS Word Formatting 3 65
Delete inline shapes featuring a specific width using VBA 13 61
vba - Word save error 11 24
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question