Harsh Kumar
asked on
VBA - Word, hide/unhide text with checkbox in userform
Hi guys,
i'm trying to hide/unhide text in the document from a userform with a checkbox...
for some reason its not working for me... this is the code i'm working with
i'm trying to hide/unhide text in the document from a userform with a checkbox...
for some reason its not working for me... this is the code i'm working with
Private Sub CommandButton1_Click()
If UserForm1.CheckBox1 = True Then
UnhideText (bm1.Range)
End If
If UserForm1.CheckBox1 = False Then
HideText (bm1.Range)
End If
If UserForm1.CheckBox2 = True Then
UnhideText (bm2.Range)
End If
If UserForm1.CheckBox2 = False Then
HideText (bm2.Range)
End If
End Sub
Public Sub HideText(ByVal rng As Word.Range)
rng.Font.Hidden = True
End Sub
Public Sub UnhideText(ByVal rng As Word.Range)
rng.Font.Hidden = False
End Sub
If you already have bm1 instantiated as a bookmark object, then your code should work, but I suspect that the bookmark name is bm1. Roy shows that with some very elegant code, but this is how you could adapt your own code:
Private Sub CommandButton1_Click()
Dim bm1 As Bookmark
Set bm1 = ActiveDocument.Bookmarks("bm1")
If UserForm1.CheckBox1 = True Then
UnhideText bm1.Range
End If
If UserForm1.CheckBox1 = False Then
HideText bm1.Range
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you guys!!! you rock!!
Glad we helped
Open in new window