在本文中,我們將重點介紹在打印Word文檔時通過VBA自動隱藏圖像和形狀的方法。
在先前的文章中,我們介紹了四種隱藏圖像和形狀以防止其被列印的方法。詳情請參閱這篇文章: 通過打印沒有圖像和形狀的Word文檔來節省墨水的4種方法
但是,前幾天我們提出的4種常用方法需要先在屏幕上隱藏圖像和形狀。 此外,您必須手動切換到Word的後台視圖才能打印文件。 此後,如果要在屏幕上保持圖像和形狀不變,則唯一的選擇是撤消所有先前的操作。
因此,我們想向您介紹宏觀的方式來幫助您節省精力。
運行宏的步驟
- 首先,點選「開發者」標籤。
- 然後單擊“ Visual Basic”以打開VBA編輯器。

- 接下來,單擊“常規”以通過單擊“插入”選項卡來插入新模塊。
- 然後選擇“模塊”。
- 現在,雙擊新創建的模塊以具有編輯區域。
- 將以下代碼粘貼到此處:
Sub PrintNoImagesOrShapesInDoc()
Dim objDoc As Document
Dim objInLineShape As InlineShape
Dim objShape As Shape
' Initialization
Set objDoc = ActiveDocument
' Find all images and shapes in the active document and then hide them to prevent from being printed.
With objDoc
For Each objInLineShape In .InlineShapes
objInLineShape.Select
Selection.Font.Hidden = True
Next objInLineShape
Options.PrintDrawingObjects = False
End With
Dialogs(wdDialogFilePrint).Show
With objDoc
For Each objInLineShape In .InlineShapes
objInLineShape.Select
Selection.Font.Hidden = False
Next objInLineShape
End With
End Sub
- 最後,單擊“運行”或單擊“ F5”。
通過單擊或敲擊,Word將提示“打印”對話框。 選擇打印屬性後,單擊“確定”進行打印。
您將獲得一個沒有圖像或形狀的文件,而電子版本保持不變。 現在,如果您需要打印多個文件(不包括圖像和形狀),可以採用這種方法。
- 首先,將所有文件整理在同一文件夾中。
- 然後重複上述所有步驟,以在VBA編輯器中安裝並運行宏,僅用此宏替換該宏:
Sub PrintMultiDocWithNoImagesAndShapes()
Dim objDoc As Document
Dim objInLineShape As InlineShape
Dim objShape As Shape
Dim strFile As String, strFolder As String
' Initialization
strFolder = "C:\Users\Public\Documents\New folder\"
strFile = Dir(strFolder & "*.docx", vbNormal)
While strFile <> ""
Set objDoc = Documents.Open(FileName:=strFolder & strFile)
' Open each doc and print it withour images and shapes.
With objDoc
For Each objInLineShape In .InlineShapes
objInLineShape.Select
Selection.Font.Hidden = True
Next objInLineShape
Options.PrintDrawingObjects = False
End With
Dialogs(wdDialogFilePrint).Show
With objDoc
For Each objInLineShape In .InlineShapes
objInLineShape.Select
Selection.Font.Hidden = False
Next objInLineShape
End With
objDoc.Save
objDoc.Close
strFile = Dir()
Wend
End Sub
備註:
在代碼行“ strFolder =“ C:\ Users \ Public \ Documents \ New folder \””中,將文件路徑替換為您實際存儲文件的文件夾之一。
修復損壞的文件的必要性
儘管文件丟失現在已不是陌生的話題,但仍有一些人破壞了文件丟失的重要性。 文檔修復有些人會直接丟棄損壞的檔案。但是,如果損壞的文件至關重要呢?眼看截止日期將近,你還有足夠的時間重新開始嗎?答案顯而易見。因此,在恢復損壞的文件時,選擇可靠的工具至關重要。
作者簡介:
陳薇薇(Vera Chen)是 DataNumen,Inc.是數據恢復技術的全球領導者,包括 損壞的XLS 以及 pdf 維修軟件產品。 欲了解更多信息,請訪問 萬維網。datanumen.COM


