In this article, we will focus on showing you the way to auto hide images and shapes via VBA when printing your Word document.
In one of our previous post, we’ve introduced 4 ways to hide images and shapes to prevent them from printing. For details, you can refer to this article: 4 Ways to Save Your Ink by Printing Word Document without Images and Shapes
However, the 4 usual ways we proposed the other day requires hiding images and shapes on screen first. What’s more, you have to manually switch to backstage view of Word to print files. After that, if you want to keep images and shapes intact on your screen, you only choice is to undo all the earlier actions.
Therefore, we’d like to present you the macro way to help you save efforts.
Steps to Run the Macro
- First and foremost, click “Developer” tab.
- Then click “Visual Basic” to open VBA editor.
- Next click “Normal” to insert a new module by clicking “Insert” tab.
- Then choose “Module”.
- Now double click the newly created module to have editing area.
- Paste the following codes there:
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
- Lastly, click “Run” or hit “F5”.
With that click or stroke, Word shall prompt the “Print” dialog box. Once you choose the print properties, click “OK” to print.
You will get a file with no images or shapes, while the electronic version remains the same. Now in case you need to print multiple files all excluding images and shapes, here is the way.
- Firstly, organize all files in the same folder.
- Then repeat all the above steps to install and run a macro in VBA editor, only to replace the macro with this one:
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
Note:
In code line “strFolder = “C:\Users\Public\Documents\New folder\””, replace the file path with an actual one of the folder you store files.
Necessity to Repair Broken Files
Though, file loss is not an alien topic now, some people still undermine the importance of doc fix. Some will just discard damaged files. But, what if it’s a real critical one? With the deadline approaching, will you have enough time to start all over again? The answer is obvious. While when it comes to retrieve bad docs, choosing a reliable tool is quite necessary.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted xls and pdf repair software products. For more information visit www.datanumen.com
Leave a Reply