Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Maximum length of  document variable using VBA in Word

Posted on 2013-11-18
2
Medium Priority
?
1,615 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 800 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

876 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