How to overcome the 255 character limit

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

How to overcome the 255 character limit
How to overcome the 255 character limit

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!


The purpose of this Microsoft Word Tips & Microsoft Word Help page will show you how you can overcome the 255 character limit is Word built-in Find and Replace dialog "Find what:" and "Replace with:" text fields.

The 255 character replace string limit is easily overcome by copying the replace string text to the clipboard and using the character code "^c" in the "Replace with:" window of the dialog box or as the .Replacement.Text value in you VBA procedure code.

Another handy method for defining any replacement text string and even a graphic is to use AutoText. Word MVP Graham Mayor and I worked out the VBA which Graham has posted on his web site here: Replace w/AutoText.  Or use the replace with AutoText option in VBA Find & Replace.

Unfortunately the character code ^c doesn't work in the "Find what" window. Even find strings constructed using wildcards are limited to 255 characters as shown below.

If you try to set a find or replace strings that are > 255 characters in length in VBA, a run-time error is generated.

I worked with Dave Lett and Helmut Weber, both former contributors the old Word VBA newsgroup, to develop a macro that would perform a find and replace routine where the text you are looking for exceeds 255 characters.

  • The process involves defining the .Find.Text string as the first 250 characters of your text.
  • If this segment is found, then the selection is extended to include the entire length of your specified text and then a comparison is made of the find text string and extended selection.
  • If a match occurs, the selection.text is replaced with the specified replacement text.

In this solution, both the find and replace strings are defined in a separate document. Here is the macro code:

How to overcome the 255 character limit
See: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.

That's it! I hope you have found this tips page useful and informative.

How to overcome the 255 character limit
How to overcome the 255 character limit

Do you want to make a payment for consulting work or donate to help support this site?

PayPal is a safe, easy way to pay online.

Use the appropriate currency "Donate" button to make a payment or donation.


The MAGIC (and Client/Server) 255 character limit makes it difficult to handle a value that exceeds this length. A reasonably common example is a URL that exceeds 255 characters.

You can use the @Call.windows or @Shell.execute macro in C/S or the %Z.link.to.shell Z program in MAGIC to pass a URL to the C/S client or MT Report Workstation and cause the PC to use the default browser to go to a website. How can you handle a case where the URL is longer than 255 characters?

There are browser add-ons (tinyurl.com) that allow you to map a small private URL to some longer URL, but this won’t work for cases where the information is dynamic, such as sending patient information to Thomson-Reuters/Micromedex to print discharge instructions. Also, a browser add-on requires installation at each PC.

One method I have used in the past is to write out a VB script file to the local PC and execute it. Security or user access restrictions on the local PC can thwart this approach.

Another method I showed in our MUSE 2011 NPR Tips and Tricks session was to write out a small “redirect” page to the PC and then use either @Shell.execute (C/S) or %Z.link.to.shell (Magic) to cause your browser to use the nice short URL of that page to then be re-directed to the true URL you need to use.

Details for this approach can be found on our website at: http://www.iatric.com/MUSE2011 in the zip file here:http://www.iatric.com/download/MUSE/MUSE2011/MUSE2011_Tips_and_Tricks.zip

For the MAGIC platform, the %Z.link.to.shell program has a new(ish) option that allows you to pass a path or URL that exceeds 255 by loading it into an array and then passing a pointer to the array to the Z program, rather than passing the URL itself.

This involves calling the Z program and passing values to it by reference instead of by value. Those of you who have taken a programming class in just about any language learned how to pass values to a procedure or function by reference. This is an essential technique for any situation in which you do not want to make a copy of some large structure or long variable and instead want to send a program a reference to an existing structure so the program works on the exact same thing, not on a copy passed by value.

In MAGIC (or C/S), you use the “name of” operator ⇒ to pass a reference to a structure, rather than its value. (The ⇒ prints as the caret ^ in a program listing, but shows up as a right pointing arrow on your Workstation screen). This is the same character as the “goes to” or “assignment” operator, but when used in the “name of” syntax, it serves as a way to pass a reference or “pointer” to a structure in a program call as one of the program arguments.

Let’s see how to load a long URL into an array and pass it to the Z.link.to.shell utility. We will create a report that has a program call in the title, and suppress the print on prompt and all message displays, so we can have a report that provides a link to the URL from a MEDITECH menu, without a confusing “Print On” prompt or “End of Report” message.

Step one is to write a dummy report. Everything happens in the title program call, so you don’t need anything in the index or detail segment fields on page 1:

How to overcome the 255 character limit

In the “d” macro, you put a 1 into /Z.SCHED.LOG (this suppresses the “Print On:” prompt) and put a 1 into /R.NO.PRT.MSGS (this gets rid of the “End of Report” message).

Then you build a list in /URL[n] (where n is an integer counter that goes 1,2,3..) of the data needed to be used as the path, URL, or command line.

How to overcome the 255 character limit

If you are an especially sharp-eyed reader, you might notice that the URL example is only 139 characters in length, but using a list /URL[n] structure allows us to build a URL of any length.

When the report runs, you go directly to the Gaylord Hotel URL in the default browser:

How to overcome the 255 character limit

This example magic report MIS.USER.zcus.is.eupdate.long.url has been posted to our report library: http://www.iatric.com/information/NPRReportLibrarySearch.aspx.

You can find additional NPR Tips on our website athttp://www.iatric.com/Information/NPRTips.aspx, as well as information about our on-site NPR Report Writer Training and NPR Report Writing Services.

Read Joe's blog posts at MEDI-Talk

To subscribe for email notifications for new classes, please follow this link:
http://www.iatric.com/Information/Classes.aspx

For more information or to reserve a seat, please contact Karen Roemer at 978-805-3142 or email .

(This article originally appeared in the October 2011 issue of Iatric Systems’ Updates! newsletter.)

Topics: 255 Character Limit, Browse to a Long URL from MAGIC, MEDITECH, NPR Tip, Report Writing Tips and Tricks

Why is there a 255 character limit?

The limit occurs due to an optimization technique where smaller strings are stored with the first byte holding the length of the string. Since a byte can only hold 256 different values, the maximum string length would be 255 since the first byte was reserved for storing the length.

How many characters can you have in an Excel cell?

Information about maximum characters count in an Excel cell An Excel cell accepts only maximum 32767 characters. ArgumentOutOfRangeException is thrown when you try to set the text with length greater that 32767 characters, into an Excel cell.