Glam Prestige Journal

Bright entertainment trends with youth appeal.

I've a word file which contains hundreds of Horizontal Lines drawn from "Insert > Shapes > Line", this document was created with earlier version of MS Word probably 2000. (currently, I'm using word 2016)

I want to delete all these lines at once, I can't select each line and hit delete for hundreds of these as I've hundreds of more documents.

Is there a way to select and delete ONLY these lines from whole document at once? Any Solution Please!

enter image description here

Thanks for you support!

EDIT: here is the link to the file Testing Horizontal Line Deletion

4

4 Answers

It seems that the code in my earlier answer is not considering the horizontal lines created in earlier version of Word as Shapes. So it does not enter the Loop in first place, so no question of deleting those lines. However I suggest another solution. Do give it a try. However take a backup of your document first.

Convert this document to latest docx or docm format by saving thru your Office 2013/2016 version first. Do not work in Compatibility Mode, else the below suggested option may not be available.

  1. On Home Ribbon Tab Go to Find --> Advanced Find
  2. Drop Down Special and select Graphic
  3. Find What text box shall hold ^g
  4. Go to Replace and enter nothing and hit Replace (to replace case by case) or Replace All to clear all in one go.

Caution - This might even replace any other Graphic. So be careful and test it out first on your document before implementing.

1

Sub This works in word 2007 for horizontal lines inserted by borders>horizontal line and won't delete other graphics:

Sub DelHorizontalLines() ' deletes lines inserted by borders>horizontal line
Dim INLINE_SHAPE As InlineShape For Each INLINE_SHAPE In ActiveDocument.InlineShapes 'OR Selection.InlineShapes With INLINE_SHAPE If INLINE_SHAPE.Type = wdInlineShapeHorizontalLine Then INLINE_SHAPE.Delete End If End With Next
End Sub

If it doesn't find your lines, delete and re-type the = and find the correct shape type in the drop down box.

In the document containing the lines CTRL+A then CTRL+C

Open a new Word document

Right-click in the white space > Paste Options > Keep Text Only

3

You can explore the below mentioned VBA Code to remove lines from your word document.

First save the document in your latest Word format as .docm (Macro enabled Word Doc).

Open the dos and press ALT + F11 to access VBA Editor. From insert menu, insert a Module. Paste the following subroutine code into it

Sub DelLines()
Dim H_Line As Shape
For Each H_Line In ActiveDocument.Shapes If H_Line.Type = msoLine Then H_Line.Delete End If
Next H_Line
End Sub

Save the document. In main doc press ALT + F8 and run this macro.

Note that - The macro somewhat gave unpredictable results on my Word 2013. It deleted all lines but one. Re-running the macro cleared the pending line. Secondly the macro seems to be unable to distinguish between line and an arrow. So it also deleted arrows. It did not touch other objects like inserted pictures or rectangles. This is attempted by selecting If H_Line.Type = msoLine Then part of the code.

So before attempting anything please take backup of your original document. Also I am not too sure how old document created in Word 2000 may respond to this code, if the code would be compatible. Try it out.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy