VB macro to locate empty pages in Word document

M

MSizlak

Unless I'm missing something, you couldn't have a page
that contained only an empty paragraph without it also
containing a page break, so I think you need only search
for page breaks. But before preceding, what do you need
to do once you find them?
Moe

-----Original Message-----
I'd appreciate some help with a macro to locate empty
pages (those containing only an empty paragraph and/or a
page break) . Various logical schemes require me to know
the line number of the insertion point as I spin through
the document. I can determine the first character of a
selection (wdFirstCharacterLineNumber) but I cannot find
a way to select one "line" at a time or to set a range
equal to a single line. This is probably available
information, since Word displays both the current
column and line number at the bottom of the
screen...but I can't find them in VB. It would help if
someone can point me to an appropriate property. Thanks.
 
D

Doug Robbins

Depending upon what is actually there, search for

^p^p^m 'last paragraph on preceding page, autolinebreak, empty paragraph,
manual page break

or it could be

^m^p^m 'manual page break, empty paragraph, manual page break

or maybe just

^m^m 'successive manual pagebreaks

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
M

MSizlak

Two apologies: (1) I didn't see your entire message the
first time; (2) The delay in my second response.

Selection.expand unit:=wdLine

This will work only with the selection object, not a
range object.

Hope that helps.

Moe
-----Original Message-----
Thanks for the prompt response. And yes, there will
always be a page break. I'm cleaning output generated by
AuthorIT, which occasionally includes a page with nothing
but a page break. When I find these, I need to delete the
page break.
 
M

MSizlak

Two apologies: (1) I didn't see your entire message the
first time; (2) The delay in my second response.

Selection.expand unit:=wdLine

This will work only with the selection object, not a
range object.

Hope that helps.

Moe
-----Original Message-----
Thanks for the prompt response. And yes, there will
always be a page break. I'm cleaning output generated by
AuthorIT, which occasionally includes a page with nothing
but a page break. When I find these, I need to delete the
page break.
 
G

Gerry Knight

You can select a line by using the "\line" bookmark, as in:

ActiveDocument.Bookmarks("\line")

It has a range property and a Start and End therefore.

In the search for "empty" pages to delete, you can use the "\page"
bookmark. It also is a range. Therefore if the Start = End - 1, then
there is only one character. If that character is "", then it is a
paragraph mark.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top