Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Sun, 5 Oct 2008 12:48:02 -0700,    group: microsoft.public.word.vba.general        back       


Form Fields are not long enough to accomodate text   
I am pushing data from Excel to Word using VBA.  In Word I have 4 form fields 
set up.  One of these fields needs to be longer than 255 chars which I 
believe is what the Maximum is (correct me if I am mistaken) allocated for 
text form fields.  Is there a workaround? I tried using a simple "bookmark" 
in section 2, but the protection of sections 1 and 3 cause the program to 
produce an error (prevents the program from writing the text to the 
bookmark).  When I unprotect section 3, the text (paragraph, rather) is 
successfully inserted.  However, unprotecting section 3 is not an option.  
Any ideas, anyone?
-- 
MD
date: Sun, 5 Oct 2008 12:48:02 -0700   author:   Lynn

Re: Form Fields are not long enough to accomodate text   
Hi Lynn,

Try something based on:
ActiveDocument.Bookmarks(“Name”).Range.Fields(1).Result.Text = "Really long string"

-- 
Cheers
macropod
[MVP - Microsoft Word]


"Lynn"  wrote in message news:3AEEB65E-9F3C-495C-9B44-D5621A4A53B0@microsoft.com...
>I am pushing data from Excel to Word using VBA.  In Word I have 4 form fields
> set up.  One of these fields needs to be longer than 255 chars which I
> believe is what the Maximum is (correct me if I am mistaken) allocated for
> text form fields.  Is there a workaround? I tried using a simple "bookmark"
> in section 2, but the protection of sections 1 and 3 cause the program to
> produce an error (prevents the program from writing the text to the
> bookmark).  When I unprotect section 3, the text (paragraph, rather) is
> successfully inserted.  However, unprotecting section 3 is not an option.
> Any ideas, anyone?
> -- 
> MD
date: Mon, 6 Oct 2008 09:27:34 +1100   author:   macropod lid

Re: Form Fields are not long enough to accomodate text   
Thanks, I will try your suggestion.
-- 
MD


"macropod" wrote:

> Hi Lynn,
> 
> Try something based on:
> ActiveDocument.Bookmarks(“Name”).Range.Fields(1).Result.Text = "Really long string"
> 
> -- 
> Cheers
> macropod
> [MVP - Microsoft Word]
> 
> 
> "Lynn"  wrote in message news:3AEEB65E-9F3C-495C-9B44-D5621A4A53B0@microsoft.com...
> >I am pushing data from Excel to Word using VBA.  In Word I have 4 form fields
> > set up.  One of these fields needs to be longer than 255 chars which I
> > believe is what the Maximum is (correct me if I am mistaken) allocated for
> > text form fields.  Is there a workaround? I tried using a simple "bookmark"
> > in section 2, but the protection of sections 1 and 3 cause the program to
> > produce an error (prevents the program from writing the text to the
> > bookmark).  When I unprotect section 3, the text (paragraph, rather) is
> > successfully inserted.  However, unprotecting section 3 is not an option.
> > Any ideas, anyone?
> > -- 
> > MD 
> 
>
date: Sun, 5 Oct 2008 16:56:01 -0700   author:   Lynn

RE: Form Fields are not long enough to accomodate text   
Lynn,

I think if you have a better understanding of what's happening in Word 
you'll be better able to come up with an acceptable solution.

First, you are correct that the character limit for formfields is 255. In 
addition, you can set the .Result property of a formfield without removing 
the protection from the document using something like:

ActiveDocument.FormFields("Text1").Result = "This is a string of less than 
255 characters."

This is the basic nature of forms protection: the only place you can add 
content to the forms-protected sections of the document is the formfields 
within the section.

However, as you have found, if the content to be added exceeds the 255 
character limit, setting the .Result property of the formfield doesn't work. 
In this instance, you have a few options available to you. You can:

*   Use the Trim function to truncate the string at 255 characters. This is 
probably not an acceptable solution since you undoubtedly want the whole 
string to appear in your document.

*   Use multiple formfields and the Mid function to parse the string into 
255 character "chunks", which then get inserted into various formfields using 
the .Result property as described above. Again, this is a less-than-optimum 
solution because it's clunky and may not produce an especially attractive 
result.

*  Use a bookmark and something like the following to insert the text:

ActiveDocument.Bookmarks("Bookmark1").Range.Text = "A long string of more 
than 255 characters."

However, as you have discovered, this method requires the section containing 
the bookmark to be unprotected (for the reasons discussed above), and you 
have stated that making this section unprotected is not an option.

The best solution is to unprotect the document prior to inserting the text 
and then reprotecting it again afterwards. The code for doing this would look 
something like:

ActiveDocument.Unprotect "password"
ActiveDocument.Bookmarks("Bookmark1").Range.Text = "A long string of more 
than 255 characters."
ActiveDocument.Protect wdAllowOnlyFormFields, True, "password"

(See the Word VBA help topics on document protection for more information on 
this code.)

Only one thing concerns me: You say that you are "pushing" data from Excel 
into Word. This makes me think that you are driving this process from the 
Excel side rather than from Word. I'm not quite sure if you will be 
successful in trying to unprotect a Word document using code from within 
Excel. This being the Word VBA forum, I suspect that most contributors would 
take the approach of "pulling" data from Excel using code in Word - and thus 
would not have to worry about this potential problem. However, some of us do 
"cross over" so maybe someone else will be able to help you with this 
possible sticking point. Otherwise, I can only suggest that you ask the 
question in the Excel VBA forum.
-- 
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all 
follow-ups to the newsgroup.


"Lynn" wrote:

> I am pushing data from Excel to Word using VBA.  In Word I have 4 form fields 
> set up.  One of these fields needs to be longer than 255 chars which I 
> believe is what the Maximum is (correct me if I am mistaken) allocated for 
> text form fields.  Is there a workaround? I tried using a simple "bookmark" 
> in section 2, but the protection of sections 1 and 3 cause the program to 
> produce an error (prevents the program from writing the text to the 
> bookmark).  When I unprotect section 3, the text (paragraph, rather) is 
> successfully inserted.  However, unprotecting section 3 is not an option.  
> Any ideas, anyone?
> -- 
> MD
date: Sun, 5 Oct 2008 18:47:01 -0700   author:   Gordon Bentley-Mix gordon(dot)bentleymix(at)gmail(dot)com

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us