0

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

  • are they contiguous, i.e. one after the other with no text between them that you want? if so then you can highlight a bunch of them really fast. – barlop Dec 14 '17 at 5:01
  • @barlop they are in table cells, the whole document is in table format, each line is in separate cell. – Qadeer Dec 14 '17 at 11:19
  • Are the rows with the lines contiguous? – barlop Dec 14 '17 at 16:14
  • I wonder if saving it in another format like RTF would help. – barlop Dec 14 '17 at 16:15
2

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.

  • it does work, even with in Compatibility Mode. Thanks @rajeev – Qadeer Dec 16 '17 at 8:18
0

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

  • By this approach, the document format won't be maintained. :(. – Qadeer Dec 13 '17 at 10:37
  • He did say he has hundreds of files so it'd be a lot of work to do that for each one even if that were to work individually. – barlop Dec 14 '17 at 16:15
  • I missed the hundreds of files bit, just saw hundreds of lines. My bad. – spikey_richie Dec 14 '17 at 16:19
0

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.

  • this snippet did nothing :( link is added to the question part – Qadeer Dec 14 '17 at 4:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.