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 / December 2006

Tip: Looking for answers? Try searching our database.

Inserting a wdFieldFormTextInput into a word table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
i.d.gibbons@googlemail.com - 05 Dec 2006 11:36 GMT
I'm having issues inserting a wdFieldFormTextInput into a word table
cell. I create the table with a macro which works perfectly. I then
need to insert a wdFieldFormTextInput into the first rows 2nd cell.

I can set the text easily enough using ..............

[code]

MyRange.Table(1).Rows(1).Cells(2).Range.Text = " Testy Text "

[/code]

I've tried multiple ways of adding the merge field all of which have
failed. I'm grateful for any advice! Here is an example of what I've
tied to do to accomplish what i'm after!

[code]

ActiveDocument.Fields.Add
Range:=MyRange.Tables(1).Rows(1).Cells(2).Range,
Type:=wdFieldFormTextInput, Text:="MERGEFIELD  TESTMERGER",
PreserveFormatting:=True

[/code]

I get the generic "Run-time error '4605': This command is not
available" error message when trying to run the above.
Helmut Weber - 05 Dec 2006 13:09 GMT
Hi,

>I've tried multiple ways of adding the merge field

so have I.
The special difficulty was, that there is no trace
of a mergefield at all in your code.

I can't recall, all that went wrong.
Whether its my fault or whether there are unrecovered bugs.

Finally, I arrived at this,
but I wonder what it could be good for.

Sub Macro9()
Dim rngTmp As Range
Set rngTmp = ActiveDocument.Tables(1).Rows(1).Cells(2).Range
ActiveDocument.FormFields.Add _
Range:=rngTmp, Type:=wdFieldFormTextInput
With ActiveDocument.FormFields
  .Item(.Count).Result = "xxx"
End With
End Sub

Creating a new formfield-object and setting its result failed.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg Maxey - 05 Dec 2006 13:43 GMT
Helmut,

You might find this interesting:

Sub RangeEffects()
Dim oRng1 As Range
Dim oRng2 As Range
Set oRng1 = ActiveDocument.Tables(1).Rows(1).Cells(1).Range
Set oRng2 = ActiveDocument.Tables(1).Rows(1).Cells(2).Range
oRng1.Collapse wdCollapseStart
With ActiveDocument
'Next line fails if oRng1 is not collapsed
 .Fields.Add oRng1, wdFieldEmpty, "MERGEFIELD TESTMERGER"
'Next line runs without error with range expanded
 .FormFields.Add oRng2, wdFieldFormTextInput
 .FormFields(1).Result = "XXX"
End With
'Here is something else odd
Set oRng1 = ActiveDocument.Tables(1).Rows(1).Cells(3).Range
With ActiveDocument
 '.Fields.Add oRng1, does not generate an intellisense dropdown of
available fields
 '.FormFields.Add oRng2, does generate an intellisense dropdown.
                         'all field types are listed.  So you can
construct
                         'the following line with intellisense:
  On Error Resume Next
  .FormFields.Add oRng1, wdFieldEmpty
  'Which understandably fails with a RTE 9, subscript out of range
  If Err.Number = 9 Then
    MsgBox "RTE " & Err.Number & " " & Err.Description
    Err.Clear
  End If
  'But this line that runs as expected can't be constructed using
intellisense!!
  .Fields.Add oRng1, wdFieldEmpty, "MergeField TestMerger"
End With
End Sub

> Hi,
>
[quoted text clipped - 29 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
Greg Maxey - 05 Dec 2006 13:10 GMT
First you can not add a field to the range of a cell.  You have to
collapse the range so that it is merely "in" the cell.  Secondly, are
you sure you want a "FormField" and not merely a Merge field?

Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Tables(1).Rows(1).Cells(2).Range
oRng.Collapse wdCollapseStart
ActiveDocument.Fields.Add oRng, Type:=wdFieldEmpty, Text:="Mergefield
TESTMERGER"
End Sub

> I'm having issues inserting a wdFieldFormTextInput into a word table
> cell. I create the table with a macro which works perfectly. I then
[quoted text clipped - 23 lines]
> I get the generic "Run-time error '4605': This command is not
> available" error message when trying to run the above.
 
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.