#1
|
|||
|
|||
Placing in a table cell text and a formfield
Hello,
I'm trying to place a text in a table cell and right after the text ( within the cell ) , a formfield ( Checkbox ) must be placed. At the moment it's not possible to do it, because the Checkbox is placed always in the next cell. I need to collapse the cell range to the end but I don't know how.. Could you help? Sorry for my poor english .. Andreas example Dim Ff As FormField, Rng As Range Set Rng = DC.Range(Start:=MainTable.Cell(14, 1).Range.Start, _ End:=MainTable.Cell(14, 1).Range.End) Set Ff = DC.FormFields.Add(Rng, wdFieldFormCheckBox) |
#2
|
||||
|
||||
It is simply a matter of moving the range as appropriate e.g.
Code:
Sub Macro1() Dim Ff As FormField, Rng As Range Dim MainTable As Table Set MainTable = ActiveDocument.Tables(1) Set Rng = MainTable.Cell(14, 1).Range Rng.End = Rng.End - 1 Rng.Text = "This is some text " Rng.Collapse 0 Set Ff = Rng.FormFields.Add(Rng, wdFieldFormCheckBox) lbl_Exit: Set Rng = Nothing Set Ff = Nothing Exit Sub End Sub Code:
Sub Macro2() Dim CC As ContentControl, Rng As Range Dim MainTable As Table Set MainTable = ActiveDocument.Tables(1) Set Rng = MainTable.Cell(14, 1).Range Rng.End = Rng.End - 1 Rng.Text = "This is some text " Rng.Collapse 0 Set CC = Rng.ContentControls.Add With CC .Type = wdContentControlCheckBox .Tag = "Check1" .Title = .Tag .Checked = False .LockContentControl = True End With lbl_Exit: Set Rng = Nothing Set CC = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thank you very much
thats it !!
Greetings from Berlin Andreas |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pasting text from Excel cell into word without creating a table, and keeping the in-cell formatting | hanvyj | Excel Programming | 0 | 08-28-2015 01:15 AM |
Assigning values to formfield checkboxes in a table | mammiano | Word Tables | 13 | 01-12-2015 06:27 AM |
How to copy userform text and formfield contents to outlook? | odin | Word VBA | 7 | 09-09-2014 11:56 AM |
Auto-populate an MS Word table cell with text from a diff cell? | dreamrthts | Word Tables | 0 | 03-20-2009 01:49 PM |