编辑:

编辑:

我有一个文档,里面全是用于显示电子表格信息的合并字段。有时我们希望手动填写这些数据,因此我们必须打印没有这些字段的文档。

有没有办法隐藏所有这些,以便我可以像它们一样打印空的

答案1

Word 中没有将合并字段设为空白的选项。只有Alt+ F9,但仍然会留下«Fieldname»空白。

因此您需要使用宏来执行此操作。您可以使用下面的宏。如果执行后不保存文档,您可以在打印后恢复到已保存的文件(带有合并字段)。当然,您也可以更改此宏以创建副本文件,执行此代码,打印并关闭副本(只需一个宏)。______如果您想要在手动填写表格的地方使用真正的空格而不是下划线字符,您可以将更改为空格。

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

编辑:

就像您在此处请求的那样,首先保存原始文件,然后“添加”到新文档,删除合并字段,打印文档并再次关闭。(一次性完成,带有一些注释)
如果您确定文档未更改,则可以跳过行.Save。但是,如果您在未保存的情况下进行了更改,则打印的副本将是保存的文件,而不是当前文件。

我已经有一段时间没有用 VBA 编码了,但我认为它正在发挥作用 ;)

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

相关内容