![]() |
|
#1
|
|||
|
|||
|
Hi guys
I do a lot of reports and I am tired of having to redo every one of them since they are the same or different at the same time... roughly what I would like to do is have a bunch of check boxes and depending if they are activated or not have the text that would be related to the box automatically follow... ex: if choose box 1 = text 1, box 2 = text 2, box 1-2 = text 3 would that be possible in Word... I know it would be in Excel but I would really need it in Word Thanks for your help and I am sorry for any misspelling I am french and I dislike Google translate |
|
#2
|
|||
|
|||
|
Probably the most straight-forward way would be a UserForm which is a vba custom dialog box.
Create a Simple Userform Any method is going to involve either complex IF fields and/or vba programming. The UserForm is the most elegant method. |
|
#3
|
|||
|
|||
|
I will try it I haven't programmed in VBA for about 10 years but if are pretty simple
Thanks |
|
#4
|
|||
|
|||
|
You can store your text for insertion in AutoText entries or simply make it a part of your checkbox result in the userform. If I want to format what is typed in response to the checkbox in a certain way, I usually do it by storing the text as an AT entry and inserting that instead.
|
|
#5
|
|||
|
|||
|
Good Idea I haden't thaught about AT entry...
I will look into how to link it from the userform checkbox to a word document Thanks you |
|
#6
|
|||
|
|||
|
Here is code I use in a UserForm with four checkboxes. It is almost ten years old but it works in Word 2003-2013.
Code:
Option Explicit
Private Sub cmdCancel_Click()
Me.Hide
Unload Me
End Sub
Private Sub cmdHelp_Click()
frmHelp.Show
End Sub
Private Sub cmdOK_Click()
If chkAlcohol.Value = True Then
MsgBox "Alcohol checked"
End If
If chkDNA.Value = True Then
UpdateBookmark "DxDNAdemand", "DxDNAdemand"
UpdateBookmark "DxDNAdemanda", "DxDNAdemand"
UpdateBookmark "DxDNAnotice", "DxDNAnotice"
Else
ClearBookmark "DxDNAdemand"
ClearBookmark "DxDNAdemanda"
ClearBookmark "DxDNAnotice"
End If
If chkOWI.Value = True Then
UpdateBookmark "DxDWI1a", "DxDWI1a"
UpdateBookmark "DxDWI1b", "DxDWI1b"
UpdateBookmark "DxDWI1c", "DxDWI1c"
UpdateBookmark "DxDWI1d", "DxDWI1d"
UpdateBookmark "DxDWI2", "DxDWI2"
UpdateBookmark "DxDWI3", "DxDWI3"
Else
ClearBookmark "DxDWI1a"
ClearBookmark "DxDWI1b"
ClearBookmark "DxDWI1c"
ClearBookmark "DxDWI1d"
ClearBookmark "DxDWI2"
ClearBookmark "DxDWI3"
End If
If chkSA.Value = True Then
UpdateBookmark "DxSAkit", "DxSAkit"
UpdateBookmark "DxSAprotocol", "DxSAprotocol"
UpdateBookmark "DxSAprotocola", "DxSAprotocol"
UpdateBookmark "DxSAprotocolb", "DxSAprotocol"
UpdateBookmark "DxSAprotocolc", "DxSAprotocol"
Else
ClearBookmark "DxSAkit"
ClearBookmark "DxSAprotocol"
ClearBookmark "DxSAprotocola"
ClearBookmark "DxSAprotocolb"
ClearBookmark "DxSAprotocolc"
End If
cmdCancel_Click
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UpdateBookmark(ByVal strBookmarkName As String, _
ByVal strAutoTextName As String)
' from http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
' modified to use AutoText by Charles Kenyon on 6 Feb 2004
' modified to use AutoText.Insert with help from Peter Hewitt on 25 Feb 2004
'
Dim rngLocation As Word.Range
Dim tplAttached As Word.Template
'
Set tplAttached = ActiveDocument.AttachedTemplate
Set rngLocation = ActiveDocument.Bookmarks(strBookmarkName).Range
Set rngLocation = tplAttached. _
AutoTextEntries(strAutoTextName).Insert(rngLocation, True)
ActiveDocument.Bookmarks.Add strBookmarkName, rngLocation
tplAttached.Saved = True
End Sub
Private Sub ClearBookmark(BookmarkToUpdate As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = ""
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
|
|
#7
|
|||
|
|||
|
Thanks for the info
|
|
#8
|
|||
|
|||
|
You are welcome.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Word2010 check boxes and plain text content control boxes in same table | fcsungard | Word | 5 | 06-01-2012 01:16 AM |
| Link word check box to access check box | Mrkieth | Word | 4 | 01-30-2012 06:43 AM |
Check Boxes
|
jellyrolls | Office | 4 | 07-15-2011 08:07 PM |
| Link 2 form items (for ex check box and a text box) | dzn | Word | 0 | 07-19-2010 01:58 AM |
| Problem with Developer Form -- Check Boxes and Text Boxes | PCC | Word | 1 | 05-16-2009 05:22 AM |