Solved

Maximum length of  document variable using VBA in Word

Posted on 2013-11-18
2
1,291 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now