1

I have a 50~ page Word document with an ActiveX checkbox on each page. I do not want these to be displayed when I print the document in any form, ie to a printer or PDF.

I have Googled around and found two examples;

Sub ChangeHidden2()
Dim doc As Word.Document
Dim rngSearch As Word.Range
Dim ffld As Word.FormField

Set doc = ActiveDocument
Set ffld = doc.FormFields("check1")
Set rngSearch = ffld.Range.Paragraphs(1).Range
rngSearch.Start = ffld.Range.End
rngSearch.Text = "Good"
End Sub

But this only hides the first checkbox, not all of them, and;

Sub HideFormsChBx()
Dim doc As Word.Document
Dim cBx As Word.FormField
Dim cntrl As Word.CheckBox

Set doc = ActiveDocument
Set cBx = doc.FormFields("Check1")
Set cntrl = doc.FormFields("Check2").CheckBox
If doc.ProtectionType <> wdNoProtection Then _
doc.Unprotect
cBx.Range.Font.Hidden = cntrl.Value
doc.Protect wdAllowOnlyFormFields, True
End Sub

Which just does not seem to work for me (various errors).

1
  • The second bode block if it contains errors is a separate problem. The first one works only for the first page since it only is perform once instead for each page and I assume you don't have multiple of the same field. Write a function that determines how many pages you in the document and change the value of ffld based on that.
    – Ramhound
    Apr 7, 2015 at 15:37

1 Answer 1

2

So finally found something which works - not the most elegant solution but it works.

Link

Create a new text style (In this example it is called "Hidden") and use this text style for any items you want to hide. Then use this code;

Private Sub CommandButton1_Click()
With ActiveWindow.View
.ShowHiddenText = False
.ShowAll = False
End With
Options.PrintHiddenText = False
With ActiveDocument
.Styles("Hidden").Font.Hidden = True
.PrintOut Copies:=1
.Styles("Hidden").Font.Hidden = False
End With
End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .