Written by Allen Wyatt (last updated December 9, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365
Anita is re-formatting a long document (over 300 pages) that was converted from PDF to Word. She has lots of experience with Word and styles and using Find and Replace to fix badly formatted documents. In this case there is a problem she can't figure out. The original document had horizontal lines in the header and footer that were converted to graphic lines in the Word document. She wants to delete all those graphic lines, but searching for ^g doesn't find them. Anita wonders if there is a way she can automate the removal of these graphic lines, as she'd rather not have to click and press Del 600+ times.
Since it appears that the PDF conversion process is adding the graphics to the header and footer, that means they are not easily "findable" by doing a regular Find and Replace. Instead, you'll want to use a macro to get rid of them. The following example looks only in the header and footer area and deletes any graphics that it finds there.
Sub FooterHeaderGraphicFind() Dim rStory As Range Dim i As Integer For Each rStory In ActiveDocument.StoryRanges If rStory.StoryType = wdPrimaryFooterStory Or _ rStory.StoryType = wdPrimaryHeaderStory Then For i = rStory.Shapes.Count To 1 Step -1 rStory.Shapes(i).Delete Next i End If Next rStory End Sub
Note that it deletes all the shapes in the header or footer, not just lines. (There is no way to differentiate the content of one graphic shape from another.)
Of course, there could be a much simpler way to handle the situation, without the need for a macro:
This approach should get rid of any type of graphic and formatting artifacts introduced into the document by the PDF conversion process. The result is a "clean" document that you can format any way you want. This approach is especially easy if you have implemented and can apply styles throughout the document.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13510) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365.
Do More in Less Time! An easy-to-understand guide to the more advanced features available in the Microsoft 365 version of Word. Enhance the quality of your documents and boost productivity in any field with this in-depth resource. Complete your Word-related tasks more efficiently as you unlock lesser-known tools and learn to quickly access the features you need. Check out Microsoft 365 Word For Professionals For Dummies today!
An object anchor is used to signify the point at which an object is inserted into a document. If you want to see these ...
Discover MoreMacros are great for processing a document just the way you want. You can even use them to insert graphics, as described ...
Discover MoreWord allows you to add watermarks to your documents. If you inherit a document that includes a watermark, you may be at a ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments