Limitation of a form field of 255 Characters

R

Ruth

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

Doug Robbins - Word MVP

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

Ruth

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

Helmut Weber

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
 
R

Ruth

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

Helmut Weber

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
 
R

Ruth

Good morning Helmut,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top