You are currently viewing the Word VBA section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
I am new to VBA and have managed to get this far using books and help files on the internet. I would like to know if it is possible to amend the code to allow this to work on multiple checkboxes, if it is possible could somebody please show me how? i.e. if i click on checkbox1 it shows the text, if i click on checkbox 2 it shows the text. I managed to amend a little but when I click on any checkbox it shows all the text and not just the text for the checbox that was ticked.
Code:
Sub CheckBox1_Change()
Call ShowHideBookmark
End Sub
Sub ShowHideBookmark()
Dim orange As Range
Set orange = ActiveDocument.Bookmarks("Bookmarkname").Range
If CheckBox1.Value = True Then
With orange.Font
.Hidden = True
End With
With ActiveWindow.View
.ShowHiddenText = False
.ShowAll = False
End With
Else
With orange.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
.ShowAll = False
End With
End If
End Sub
Sub CheckBox1_Change()
Call ShowHideBookmark(CheckBox1)
End Sub
Sub ShowHideBookmark(ByRef CB)
Dim orange As Range
Set orange = ActiveDocument.Bookmarks("Bookmarkname").Range
If CB.Value = True Then
With orange.Font
.Hidden = True
End With
With ActiveWindow.View
.ShowHiddenText = False
.ShowAll = False
End With
Else
With orange.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
.ShowAll = False
End With
End If
End Sub