Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2018, 12:07 AM
andi_bln andi_bln is offline Placing in a table cell text and a formfield Windows 7 64bit Placing in a table cell text and a formfield Office 2010 64bit
Novice
Placing in a table cell text and a formfield
 
Join Date: Oct 2015
Location: Berlin
Posts: 8
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 Placing in a table cell text and a formfield Windows 10 Placing in a table cell text and a formfield Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
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) (2002-2019)
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 Placing in a table cell text and a formfield Windows 7 64bit Placing in a table cell text and a formfield Office 2010 64bit
Novice
Placing in a table cell text and a formfield
 
Join Date: Oct 2015
Location: Berlin
Posts: 8
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
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
Placing in a table cell text and a formfield 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft