Solved

Maximum length of  document variable using VBA in Word

Posted on 2013-11-18
2
1,433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
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 …
Suggested Courses

739 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