Apr 3, 2015 - If you later want to remove the line, it helps to understand how Word. I'm editing a MS Word 2010 document that has multiple horizontal lines.
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! Thanks for you support! EDIT: here is the link to the file.
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. On Home Ribbon Tab Go to Find - Advanced Find. Drop Down Special and select Graphic. Find What text box shall hold ^g. 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. 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 HLine As Shape For Each HLine In ActiveDocument.Shapes If HLine.Type = msoLine Then HLine.Delete End If Next HLine 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 HLine.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.