Consulting

Results 1 to 6 of 6

Thread: Linking userform with MS word

  1. #1
    VBAX Newbie
    Joined
    Aug 2015
    Posts
    3
    Location

    Linking userform with MS word

    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.

  2. #2
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Aug 2015
    Posts
    3
    Location
    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.

  4. #4
    VBAX Newbie
    Joined
    Aug 2015
    Posts
    3
    Location
    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.

  5. #5
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    VBAX Regular
    Joined
    Feb 2015
    Posts
    81
    Location
    yuva24,

    You might want to check threads 52044 and 53890.

    gmayor was a huge help with those also.

    Chunk

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •