I hope that is not the only code you have!!!! You need to be very careful about where the Selection point is when you run that. If you run it anywhere that there is text BEFORE the Selection, then it is an infinite loop and the code will never stop.
Yes it works fine if there is ONLY blank lines before the Selection. But if there is not.... Say you have:
blank line
blank line
blank line
Text text text 1111
blank line
blank line
blank line
blank line
Text 22222
blank line
blank line
blank line
If you run your code at the end, it will remove "blank lines" up to "Text 22222" and then merrily continue forever in the loop.
One way to make this not happen would be to put Selection.HomeKey Unit:=wdStory to make sure the Selection goes to the beginning of the document.
You shouldn't have so many documents with blank lines at the beginning that you need a macro for this rather trivial exercise. Yes, I know there are several ways for it to happen (click and type, for example) but happening, on a regular basis, when you don't want it suggests an automatic process may be creating them, in which case you should probably try to address that process instead of trying to provide a post hoc fix.
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
I didn't even want to address the WHY of this. I completely agree. I wonder why there would even be "blank lines". A well put together document would not have any in the first place.
I have a document that is created from access, using an almost find and replace method to complete the relevant spaces. Yes I know that a mailmerge could have been used but without going into it there were too many issues with it.
The top line of the document tempplate has a few characters which the find and replace code needs, so that it knows what it is looking for and this is enclosd in < and >. Once the macro has run and done what it does the top line is replaced with "", hence leaving a blank line or two.
Also the selection will always be at the top as I have set it to be there.
If you have any other questions or comments please feel free to post.
OK, seems reasonable to me. My post was in response to seeing the code in isolation. That is why I asked if there was other code...which...there is. Someone using the code you posted, by itself, may have had problems. And...yes, I can now see why there would be blank paragraphs (I hate the use of the term "line"), and why you would want to get rid of them.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.