How to Auto Hide Images and Shapes via VBA when Printing Your Word Document

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

  1. First and foremost, click “Developer” tab.
  2. Then click “Visual Basic” to open VBA editor.Click "Developer"->Click "Visual Basic"
  3. Next click “Normal” to insert a new module by clicking “Insert” tab.
  4. Then choose “Module”.Click "Normal"->Click "Insert"->Click "Module"
  5. Now double click the newly created module to have editing area.
  6. 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
  1. Lastly, click “Run” or hit “F5”.Paste codes->Click "Run"

With that click or stroke, Word shall prompt the “Print” dialog box. Once you choose the print properties, click “OK” to print.Set Print Properties->Click "OK"

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.

  1. Firstly, organize all files in the same folder.
  2. 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

Your email address will not be published. Required fields are marked *