Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-26-2018, 12:07 AM
andi_bln andi_bln is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Oct 2015
Posts: 5
andi_bln is on a distinguished road
Default 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)
Reply With Quote
  #2  
Old 10-26-2018, 12:29 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,705
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

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
Personally I would recommend using content controls rather than form fields so
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)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 10-26-2018, 12:37 AM
andi_bln andi_bln is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Oct 2015
Posts: 5
andi_bln is on a distinguished road
Smile Thank you very much

thats it !!


Greetings from Berlin

Andreas
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning values to formfield checkboxes in a table 6packma Word 5 08-01-2018 04:02 PM
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


All times are GMT -7. The time now is 09:37 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft