Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Limitation of a form field of 255 Characters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ruth - 12 Jan 2008 18:10 GMT
Hi!!

I am trying to use a macro to fill in a field in a form with a paragraph I
copy from an EXCEL cell. The problem is that this paragrph has more than 255
characters so it doesn't seem to work directly. I have seen some article that
sugest to use the clipboard as a way to overcome this problem. Then, the code
I have programmed is as follows:

Range("T"&fila) returns the paragraph from the EXCEL cell.
wdFF is defined as Object in wordFile.Formfields.
rngx is defined as Range

                If Len(Range("T" & fila)) > 255 Then
                 wdFF.Result = Left$(Range("T" & fila), 250)
                 MyDataObj.SetText ""
                 MyDataObj.PutInClipboard
                 MyDataObj.SetText Mid$(Range("T" & fila), 256)
                 MyDataObj.PutInClipboard
                 Set rngx = wdFF.Range
                 rngx.GoTo
                 rngx.Select
                 With wordFile.Selection
                   .Collapse wdCollapseEnd
                   .Paste
                 End With
               Else
                  wdFF.Result = Range("T" & fila)
               End If

The macro works fine until it arrives to the sentence  "Set rngx =
wdFF.Range" where it stops and says that formats are not compatible  (rngx is
defined as a range). Any idea of how to solve the problems with the code?
Does the rest of the code for the macro look fine?
Doug Robbins - Word MVP - 12 Jan 2008 20:35 GMT
' Macro created 05/09/98 by Doug Robbins to insert long string into
FormField

'

FillText = "Your long string"

LenFillText = Len(FillText)

FirstBit = Left(FillText, 255)

If LenFillText > 255 Then

   SecondBit = Mid(FillText, 256, LenFillText - 255)

   ActiveDocument.FormFields("Text1").Result = FirstBit

   Selection.GoTo What:=wdGoToBookmark, Name:="Text1"

   ActiveDocument.Unprotect

   Selection.InsertAfter SecondBit

   ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

Else

   ActiveDocument.FormFields("Text1").Result = FillText

End If

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi!!
>
[quoted text clipped - 33 lines]
> defined as a range). Any idea of how to solve the problems with the code?
> Does the rest of the code for the macro look fine?
Ruth - 13 Jan 2008 01:30 GMT
Thanks for your help!!
I used your code but I still get a runtime error 438 "Object doesn't support
property or method". Just to make it clear the macro is programmed in EXCEL
and opens the word document from there. Any idea of why this error???

> ' Macro created 05/09/98 by Doug Robbins to insert long string into
> FormField
[quoted text clipped - 64 lines]
> > defined as a range). Any idea of how to solve the problems with the code?
> > Does the rest of the code for the macro look fine?
Helmut Weber - 13 Jan 2008 12:03 GMT
Hi Ruth,

have you declared rngx as Word.range ?

Otherwise it will be an Excel.range.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Ruth - 13 Jan 2008 13:08 GMT
Well Helmut good question!!
I have defined it as usual
Dim rngx as Range
so, probably it is defined as an Excel range. How do I define it as a word
range? I tried with Dim rngx as Word.Range but it doesn't work at all ....
Thanks for your help!!

> Hi Ruth,
>
[quoted text clipped - 9 lines]
>
> Vista Small Business, Office XP
Helmut Weber - 13 Jan 2008 13:49 GMT
Hi Ruth,

>so, probably it is defined as an Excel range. How do I define it as a word
>range? I tried with Dim rngx as Word.Range but it doesn't work at all ....

it depends on the way you access Word.
see:
http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

in principle, once you have got a Word-object
dim WrdRange as <WordObject>.range

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Ruth - 14 Jan 2008 08:58 GMT
Good morning Helmut,

Thanks for your help. That was the problem. I changed that and it worked fine.

> Hi Ruth,
>
[quoted text clipped - 15 lines]
>
> Vista Small Business, Office XP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.