lundi 11 septembre 2023

Word 2016 VBA: UserForm Checkbox Feeds 2nd MSDOC Checkbox

Title: Word 2016: VAB Checkbox: Display a variable of a UserForm CheckBox to another variable CheckBox inside the overlying Word Doc.

I have a Word Document that has 6 Checkboxes as 2 sets of 3 each to choose between. (i,e. yes/no and does/does not) Each set of the Checkboxes are verified to only have one box checked with the below code, as well as other fill in the form - text variables.

To simplify filling the document, I chose to "Create" a UserForm with 6 Checkboxes and other text data fields. Each 6 variables from the UserForm checkbox are assigned variable named Checkbox1 thru Checkbox 6.

Private Sub Checkbox1_Click() 
       If Checkbox1.Value = True Then
   Checkbox2.Value = False
End If 
End Sub

Private Sub Checkbox2_Click() 
       If Checkbox2.Value = True Then
   Checkbox1.Value = False
End If 
End Sub

Once all data is entered and boxes checked in the UserForm, the OK Button is pressed, which runs the VAB code to fill in the overlaying Word Document with all the variables including the selected Checkboxes1-6.

PROBLEM: When the OK Button is clicked, All the text (which is assigned to various variables) BUT: None of the Checkbox are filled on the overlying Word Document.

Current Sample of many tries what I have tried, but the .Text can’t be changes to the correct VBA object type .Checkbox

Private Sub ToggleButtonOK_Click()

Dim COTTPower1 As Range
If Checkbox1 = True Then
    Set COTTPower1 = ActiveDocument.Bookmarks(True).Range
Else
    Set COTTPower1 = ActiveDocument.Bookmarks(False).Range
End If

COTTPower1.Text = Me.CheckBox1.Value
 .
 .
 .        
      {Repeat of the checkbox VBA Coding with changing variables.}
 .
 .
 .

End Sub

Can anyone help with the appropriate code to accomplish this task?




Aucun commentaire:

Enregistrer un commentaire