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?

Re: Limitation of a form field of 255 Characters by Doug

Doug
Sat Jan 12 12:35:42 PST 2008

' 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


--
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

"Ruth" <Ruth@discussions.microsoft.com> wrote in message
news:CB2533E7-0072-4FEB-97C7-94A2D3305ADF@microsoft.com...
> 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?



Re: Limitation of a form field of 255 Characters by Ruth

Ruth
Sat Jan 12 17:30:01 PST 2008

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???

"Doug Robbins - Word MVP" wrote:

> ' 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
>
>
> --
> 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
>
> "Ruth" <Ruth@discussions.microsoft.com> wrote in message
> news:CB2533E7-0072-4FEB-97C7-94A2D3305ADF@microsoft.com...
> > 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?
>
>
>

Re: Limitation of a form field of 255 Characters by Helmut

Helmut
Sun Jan 13 04:03:51 PST 2008

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

Re: Limitation of a form field of 255 Characters by Ruth

Ruth
Sun Jan 13 05:08:01 PST 2008

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!!

"Helmut Weber" wrote:

> 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
>

Re: Limitation of a form field of 255 Characters by Helmut

Helmut
Sun Jan 13 05:49:30 PST 2008

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

Re: Limitation of a form field of 255 Characters by Ruth

Ruth
Mon Jan 14 00:58:00 PST 2008

Good morning Helmut,

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



"Helmut Weber" wrote:

> 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
>