{"id":12200,"date":"2022-04-18T17:32:45","date_gmt":"2022-04-18T21:32:45","guid":{"rendered":"http:\/\/nycphantom.com\/journal\/?p=12200"},"modified":"2022-04-18T17:42:49","modified_gmt":"2022-04-18T21:42:49","slug":"form-fields-in-ms-word-have-255-character-limit","status":"publish","type":"post","link":"http:\/\/nycphantom.com\/journal\/?p=12200","title":{"rendered":"Form Fields in MS Word have 255 character limit"},"content":{"rendered":"\n<p>So with my school database that generates a word document for Final Report for students, it hit a wall with narrative\/comments from teachers that's over 255 characters long. Instead of complaining long winded commentaries, I just had to fix this.<\/p>\n\n\n\n<p>The <a rel=\"noreferrer noopener\" href=\"https:\/\/microsoft.public.word.vba.general.narkive.com\/N4BR87UH\/form-fields-are-not-long-enough-to-accomodate-text\" target=\"_blank\">best solution page<\/a>, that is thorough enough, I am pasting its content here, lest it's taken down: (I basically just used ActiveDocument.Bookmarks(\"Bookmark1\").Range.Text Instead of .FormFields(\"Bookmark1\").Result.<\/p>\n\n\n\n<p>Lynn,<\/p>\n\n\n\n<p>I think if you have a better understanding of what's happening in Word<br>you'll be better able to come up with an acceptable solution.<\/p>\n\n\n\n<p>First, you are correct that the character limit for formfields is 255. In<br>addition, you can set the .Result property of a formfield without removing<br>the protection from the document using something like:<\/p>\n\n\n\n<p>ActiveDocument.FormFields(\"Text1\").Result = \"This is a string of less than<br>255 characters.\"<\/p>\n\n\n\n<p>This is the basic nature of forms protection: the only place you can add<br>content to the forms-protected sections of the document is the formfields<br>within the section.<\/p>\n\n\n\n<p>However, as you have found, if the content to be added exceeds the 255<br>character limit, setting the .Result property of the formfield doesn't work.<br>In this instance, you have a few options available to you. You can:<\/p>\n\n\n\n<p>* Use the Trim function to truncate the string at 255 characters. This is<br>probably not an acceptable solution since you undoubtedly want the whole<br>string to appear in your document.<\/p>\n\n\n\n<p>* Use multiple formfields and the Mid function to parse the string into<br>255 character \"chunks\", which then get inserted into various formfields using<br>the .Result property as described above. Again, this is a less-than-optimum<br>solution because it's clunky and may not produce an especially attractive<br>result.<\/p>\n\n\n\n<p>* Use a bookmark and something like the following to insert the text:<\/p>\n\n\n\n<p>ActiveDocument.Bookmarks(\"Bookmark1\").Range.Text = \"A long string of more<br>than 255 characters.\"<\/p>\n\n\n\n<p>However, as you have discovered, this method requires the section containing<br>the bookmark to be unprotected (for the reasons discussed above), and you<br>have stated that making this section unprotected is not an option.<\/p>\n\n\n\n<p>The best solution is to unprotect the document prior to inserting the text<br>and then reprotecting it again afterwards. The code for doing this would look<br>something like:<\/p>\n\n\n\n<p>ActiveDocument.Unprotect \"password\"<br>ActiveDocument.Bookmarks(\"Bookmark1\").Range.Text = \"A long string of more<br>than 255 characters.\"<br>ActiveDocument.Protect wdAllowOnlyFormFields, True, \"password\"<\/p>\n\n\n\n<p>(See the Word VBA help topics on document protection for more information on<br>this code.)<\/p>\n\n\n\n<p>Only one thing concerns me: You say that you are \"pushing\" data from Excel<br>into Word. This makes me think that you are driving this process from the<br>Excel side rather than from Word. I'm not quite sure if you will be<br>successful in trying to unprotect a Word document using code from within<br>Excel. This being the Word VBA forum, I suspect that most contributors would<br>take the approach of \"pulling\" data from Excel using code in Word - and thus<br>would not have to worry about this potential problem. However, some of us do<br>\"cross over\" so maybe someone else will be able to help you with this<br>possible sticking point. Otherwise, I can only suggest that you ask the<br>question in the Excel VBA forum.<br>--<br>Cheers!<br>Gordon<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So with my school database that generates a word document for Final Report for students, it hit a wall with narrative\/comments from teachers that's over 255 characters long. Instead of complaining long winded commentaries, I just had to fix this. &hellip; <a href=\"http:\/\/nycphantom.com\/journal\/?p=12200\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-12200","post","type-post","status-publish","format-standard","hentry","category-technical"],"_links":{"self":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/12200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12200"}],"version-history":[{"count":2,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/12200\/revisions"}],"predecessor-version":[{"id":12203,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=\/wp\/v2\/posts\/12200\/revisions\/12203"}],"wp:attachment":[{"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12200"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nycphantom.com\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}