PDA

View Full Version : Linking userform with MS word



yuva24
08-09-2015, 08:38 PM
Hi All,

Please help in solving my problem, I am very new to this VBA coding.

I am writing a vba code, in which i am trying to link the userfrom with the MS word.

I have a checklist in the ms word with checkboxes & Textboxes, wherein i want the users to provide data by checking the checkboxes in checklist. I thought to create the checklist in userform (within word). I have created the userform as same as the checklist in the ms word. Now if the user checks the check box 1 in the userform i want the same checkbox to be checked in ms word, Link the userform with MS Word.

since i need to take a print of the checklist, i want the same in ms word.

Please help me in solving this vba code.

Note: I knew that the checklist in the word document can be printed,rather creating an userform, but i have textboxes where users needs to provide the comments in the textboxes, these comments needs to be collated in a separate word document (not in the checklist).

Thanks in advance.

gmayor
08-09-2015, 09:05 PM
Let's assume that you have a simple userform with check boxes and a command button with default names, and in the document you have inserted check box content controls with tags of Check1 and Check2 etc. The userform code would be
Option Explicit

Private Sub CommandButton1_Click()
Me.Hide
Me.Tag = 1
End Sub

In an ordinary module the following macro would call the form and process two check boxes - add as many other check boxes as required using similar syntax.


Option Explicit
Sub RunUserform()
Dim oFrm As New UserForm1
Dim oCTRL As ContentControl
With oFrm
.Show
If .Tag = 1 Then
For Each oCTRL In ActiveDocument.ContentControls
If oCTRL.Type = wdContentControlCheckBox Then
oCTRL.Checked = False
End If
Next oCTRL
If .CheckBox1.Value = True Then
For Each oCTRL In ActiveDocument.ContentControls
If oCTRL.Tag = "Check1" Then
oCTRL.Checked = True
Exit For
End If
Next oCTRL
End If
If .CheckBox2.Value = True Then
For Each oCTRL In ActiveDocument.ContentControls
If oCTRL.Tag = "Check2" Then
oCTRL.Checked = True
Exit For
End If
Next oCTRL
End If
End If
End With
Unload oFrm
Set oFrm = Nothing
End Sub

yuva24
08-09-2015, 09:34 PM
Thanks Graham,

Thanks for providing me with the code. I have another question, as I said earlier, I am creating a userform as same as the word document (kind of Checklist), with the help of this userform, users will provide their inputs. The userform consists of Checkboxes and Textboxes. I need their inputs to be captured in the word document on a click of a button.

Hope you understand my query

Thanks in advance.

yuva24
08-09-2015, 09:47 PM
Hi Graham,

In addition to the above query, the checkboxes and the textboxes in the word documents are in table format, the inputs provided by the user has to be placed in the right table in the word.

thanks in advance for solving my query.

gmayor
08-10-2015, 12:01 AM
See http://www.gmayor.com/Userform.htm which covers a variety of ways of inserting data from the userform. The code shown, has the process associated with the command button, but it is a simple substitution to add it to the macro I posted earlier instead.

Chunk
10-06-2015, 09:33 AM
yuva24,

You might want to check threads 52044 and 53890.

gmayor was a huge help with those also.

Chunk