PDA

View Full Version : Show/Hide paragraph in word if Checkbox selected



DavG63
07-22-2014, 01:51 PM
Hi

Thanks for reading. I'm very new to VBA, less than a week, so please bear with me if my query doesn't make sense.

I have a standardised form ("Notice") that I use for work, which up until now has just been completed and amended by hand. I have been able to design a Userform which Initialises immediately when the Notice is opened and which contains textboxes for name, address and so on.

At the end of the Notice, there can be three possible final paragraphs dependant upon what the user needs. What I'd like to be able to do is to add three checkboxes to my Userform so that if one is selected, when I then press 'OK' and the DocVariables are updated in the Notice, the document would show the relevant paragraph. I've seen mention made of using hidden text and also using bookmarks - though I haven't quite been able to figure out how to make it work. One thing I would mention is that I don't have network access to create Autotexts or access the Building Blocks Organiser.

I would be so grateful if someone could point me in the right direction to solving this.

Thanks again.

Dav

ranman256
07-23-2014, 01:34 PM
You could put the texts in text boxes. All are hidden , except the one you want...


Sub Show1Box(ByVal pyBoxNum As Byte)
Dim shp
For Each shp In ActiveDocument.Shapes
shp.Visible = shp.Name = "txtBox" & pyBoxNum
Next
End Sub
Sub ShowAllTextBoxes()
For Each shp In ActiveDocument.Shapes
shp.Visible = True
Next
End Sub
Sub NumberAllBoxes()
For Each shp In ActiveDocument.Shapes
i = i + 1
shp.Name = "txtBox" & i
'MsgBox shp.TextFrame.TextRange.Text, , shp.Name
Next
End Sub