SwatiB
09-20-2017, 06:40 AM
Hi,
I am extremely new to VBA coding, specially for Word. I have to write a code where based on the users selection, one para gets removed or remains in the document. My code works only once. I have used bookmarks and once the para is deleted if the user chooses option 1 again, i dont know how to reinsert the bookmark. I am alternatively also trying to build a userform with combobox, i dont know if I use Cases to define this maybe it will work. Please advise.
Here is my code till now:
Sub CheckBox1_Click()
Dim answer1 As Long
'This will return what happens when the CP Manager check box (first checkbox)is clicked.
If (CheckBox1.Value = True) Then
answer1 = MsgBox("Are you a CP Manager", vbYesNo + vbQuestion, "Please check your choice")
If answer1 = vbYes Then
MsgBox ("Please read through the document")
ActiveDocument.Bookmarks("Reg_comp").Range.Font.Hidden = True
With Selection
.GoTo What:=wdGoToBookmark, Name:="Start"
End With
Else
MsgBox ("Please select option 2")
End If
Else: CheckBox2_Click
End If
CheckBox1.Value = False
End Sub
Private Sub CheckBox2_Click()
Dim answer2 As Long
If CheckBox2.Value = True Then
answer2 = MsgBox("Are you a CoC Manager", vbYesNo + vbQuestion, "Please check your choice")
CoC
Else
MsgBox ("Please select option 1")
End If
End Sub
Sub CoC()
With Selection
.GoTo What:=wdGoToBookmark, Name:="Reg_comp"
Selection.Delete
.GoTo What:=wdGoToBookmark, Name:="Start"
End With
CheckBox2.Value = False
End Sub
I am extremely new to VBA coding, specially for Word. I have to write a code where based on the users selection, one para gets removed or remains in the document. My code works only once. I have used bookmarks and once the para is deleted if the user chooses option 1 again, i dont know how to reinsert the bookmark. I am alternatively also trying to build a userform with combobox, i dont know if I use Cases to define this maybe it will work. Please advise.
Here is my code till now:
Sub CheckBox1_Click()
Dim answer1 As Long
'This will return what happens when the CP Manager check box (first checkbox)is clicked.
If (CheckBox1.Value = True) Then
answer1 = MsgBox("Are you a CP Manager", vbYesNo + vbQuestion, "Please check your choice")
If answer1 = vbYes Then
MsgBox ("Please read through the document")
ActiveDocument.Bookmarks("Reg_comp").Range.Font.Hidden = True
With Selection
.GoTo What:=wdGoToBookmark, Name:="Start"
End With
Else
MsgBox ("Please select option 2")
End If
Else: CheckBox2_Click
End If
CheckBox1.Value = False
End Sub
Private Sub CheckBox2_Click()
Dim answer2 As Long
If CheckBox2.Value = True Then
answer2 = MsgBox("Are you a CoC Manager", vbYesNo + vbQuestion, "Please check your choice")
CoC
Else
MsgBox ("Please select option 1")
End If
End Sub
Sub CoC()
With Selection
.GoTo What:=wdGoToBookmark, Name:="Reg_comp"
Selection.Delete
.GoTo What:=wdGoToBookmark, Name:="Start"
End With
CheckBox2.Value = False
End Sub