1

I have a document full of merge fields that are used to display information from a spreadsheet. Sometimes we want this data to be filled manually, so we have to print the document without these fields.

Is there any way of hiding all of them so I can print like they are empty?

0
1

There is no option to make mergefields blank in Word. There is only Alt+F9 but that still leaves you with «Fieldname» instead of blanks.

So you need to do this with a macro. You can use the macro below. If you don't save the document after executing, you can revert back to your saved file (with mergefields) after printing. Of course you could also change this macro to create a copy-file, execute this code, print and close the copy (al with one macro). You can change the ______ to a space if you want real blanks instead of underline characters on the place to fill out the form manually.

Sub Demo()
Dim oFld As Field
For Each oFld In ActiveDocument.Fields
  With oFld
    If .Type = wdFieldMergeField Then
      .Code.Text = "QUOTE " & Chr(34) & "______" & Chr(34)
      .Update
      .Unlink
    End If
  End With
Next
End Sub

Edit:

Like you requested here an example where the original file is first saved, then "added" to a new document, mergefields deleted, document printed and closed again. (all in one go, with some comments)
If you are sure the document is not changed you could skip the .Save-line. But then if you made changes without saving, your printed copy will be of the saved file, not your current file.

It's been a while since i coded in VBA but i think it's working ;)

Sub PrintCopyWithoutMergeFields()
  Dim oFld As Field

  ' save the original, needs to be done to add it as copy
  ActiveDocument.Save

  ' copy the original to a new document
  Application.Documents.Add ActiveDocument.FullName

  ' loop through all the fields and delete mergefields
  For Each oFld In ActiveDocument.Fields
    With oFld
      If .Type = wdFieldMergeField Then
        .Code.Text = "QUOTE " & Chr(34) & "______" & Chr(34)
        .Update
        .Unlink
      End If
    End With
  Next

  ' print the copy with the print-dialog
  Dialogs(wdDialogFilePrint).Show

  ' if you don't want the print-dialog, use this for the default printer
  ' Application.PrintOut

  ' close the copy without asking to save
  ActiveDocument.Close False

End Sub
2
  • Works like a charm, thanks. Would it be too hard to make this macro create a new document before deleting all the fields? – vmassuchetto Nov 14 '13 at 16:21
  • @ViniciusMassuchetto I added an example to my answer with copying and printing and closing the copy again. (with some comments, too) – Rik Nov 14 '13 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.