|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
I have created a word UserForm that has multiple checkboxes. I want the value of those checkboxes to appear on my word document next to a bookmark value. However, right now only one value is displayed on my document
Dim oCtrl As Control Dim NeededForms As Range Set NeededForms = ActiveDocument.Bookmarks("NeededForms").Range For Each oCtrl In NeededForms1.Controls If TypeName(oCtrl) = "CheckBox" Then If oCtrl.Value = True Then NeededForms.Text = oCtrl.Caption Exit For End If End If Next Unload Me Repaint End Sub |
#2
|
||||
|
||||
As written, the code should keep replacing the same range until it does the final caption (this happens faster than you can see). If you want it to keep adding then insert the text after the range or keep adding to the end or start of the range.
For example: NeededForms.InsertAfter vbCr & oCtrl.Caption
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thank you for replying. I am new to vb code so I am unsure exactly where to insert your suggested line of code or if I need to omit some of mine. I want the caption of any checkbox that is checked to display on the document. Example: Form Needed: Signature form, Content form, Worklist form. What I get s just on forms captions displaying.
|
#4
|
||||
|
||||
It replaces the line that says
NeededForms.Text = oCtrl.Caption
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
It's still only putting one checkbox caption in. Not sure why?
|
#6
|
||||
|
||||
How many checkboxes were checked when the macro ran?
You need to post a document or template with the code and userform if you need someone to solve your problem.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
Reply
I have all three checked and the middle checkbox is the only one that appears next to the bookmark when I check all three. The template is simple just has a bookmark where that information needs to go.
|
#8
|
|||
|
|||
I also wanted to add a reset button to the template so you don't have to close the document and re-open it every time you want to use the user form again with a fresh document, but it doesn't appear that there are very good resources for vb coding where it pertains to the bookmarks. So I am up against that obstacle.
|
#9
|
|||
|
|||
Form
Attachment of a section of the form and its output only displaying the caption from the second box.
|
#10
|
|||
|
|||
Maybe because 'Exit for' once it finds a checkbox=true, the rest are not being analyzed.
__________________
Backup your original file before doing any modification. |
#11
|
||||
|
||||
Cross-posted at: VBA UserForm for Word Mulitple checkboxes not all displaying on document | MrExcel Message Board
For cross-posting etiquette, please read: A message to forum cross posters - Excelguru
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
Reply
I had no idea MrExcel and MsOfficeForums were connected. I posted on MrExcel because I believed it was a completely different site and I am trying to get help. I had no intentions of Cross-posting.
|
#13
|
||||
|
||||
They are different sites, which is the whole point. Please read the link I provided.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#14
|
|||
|
|||
The one displaying is the second on checked which I find odd. I would think it would have used the last one checked, but it always returns the text from the second box.
|
#15
|
|||
|
|||
I read through your message. I am very confused and new to these message boards. All in all, I am unsure why or how my internet activity is being monitored on a completely different site. All in all, I went elsewhere days after this post because the solution was not working. It is working now that the last person told me to remove the for statement.
|
Tags |
checkboxes, word user form |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
ms word document text translation using vba code | pk_00 | Word VBA | 1 | 03-02-2020 03:11 PM |
The Word userform checkbox (checked/unchecked) is not saved on the Application Quit | matapagi2019 | Word VBA | 3 | 03-31-2019 02:29 AM |
Creating a letter in Word, with text pulled from an Excel document based on selections in a userform | TMAL | Word VBA | 6 | 12-15-2017 02:16 PM |
Template opens with userform ; non-checked boxes should lead to deletion of corresp paragraphs | samszaf | Word | 1 | 09-07-2015 09:52 AM |
VBA Code in a UserForm module to delete a Command Button which opens the userform | Simoninparis | Word VBA | 2 | 09-21-2014 03:50 AM |