Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Removing blank spaces and section breaks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Denise - 01 Nov 2004 16:47 GMT
Hello

Using Office 2002 SP-2, Windows 2000 V5.0 SP-4.

I have a Word template with a userform where users can tick checkboxes to
include blocks of text.  If a box is left unticked the corresponding block
of text is deleted from the document.  The document initially contains all
the text and pieces are removed if their box is unticked.

My problem is that I am left with large blank spaces in the document which
need to be removed.  Also, if an entire section has been deleted I need to
remove the section break as well.

I haven't been able to find a way of doing this through VBA and would very
much appreciate any help.

Thanks

Denise Crawley
Jay Freedman - 01 Nov 2004 17:27 GMT
Hi Denise,

You'll need to supply more information. It depends on how the template is
set up and how the code in the userform is doing the deletions.

Are the blocks of text initially surrounded by bookmarks, and is the code
using something like this?
 ActiveDocument.Bookmarks("bookmarkname").Range.Delete
Or is there some other arrangement that tells the code which text to remove?

After the code has removed a block, look at the document with nonprinting
characters turned on. What's causing the blank spaces? Are there empty
paragraphs, paragraphs with large Space Before or with Page Break Before
turned on, hard page breaks, Next Page section breaks, or something else?

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hello
>
[quoted text clipped - 16 lines]
>
> Denise Crawley
Denise - 01 Nov 2004 17:49 GMT
> Hi Denise,
>
[quoted text clipped - 10 lines]
> paragraphs, paragraphs with large Space Before or with Page Break Before
> turned on, hard page breaks, Next Page section breaks, or something else?

Hi Jay, thanks for the speedy response

You're spot-on about the bookmarks - that's exactly how I've done it.  The
code is as follows:-

Private Sub RemoveSection(strBookmark As String)
   
   ' Searches for a bookmark named strBookmark and removes it if found
   
   On Error GoTo Err_RemoveSection
   
   If ActiveDocument.Bookmarks.Exists(strBookmark) Then
       
       ActiveDocument.Bookmarks(strBookmark).Select
       Selection.Delete
       
   End If
   
Exit_RemoveSection:
   
   Exit Sub
   
Err_RemoveSection:
   
   With Err
       
       MsgBox "Error no. " & .Number & vbCr & _
           "in function RemoveSection" & vbCr & .Description
       
   End With
   
   Resume Exit_RemoveSection
   
End Sub

I've had a look at the remaining blanks with Show/Hide On.  There is a
single paragraph mark at the top of each page but the rest of each page is
blank, i.e. no non-printing chars.  Some pages have the paragraph mark then
a page break, some have a section break but many of the pages are blank
apart from the paragrpah mark.  I must admit this is a real grey area for
me so I'm not really sure what this tells you.

Does this help and is there any more information I can give you?
Jay Freedman - 01 Nov 2004 20:05 GMT
>> Hi Denise,
>>
[quoted text clipped - 59 lines]
>
> Does this help and is there any more information I can give you?

Hi Denise,

For the issue of deleting the section breaks along with the text, the answer
is to set up the template so the section break *at the end* of each text
block is *inside* the bookmark and will be deleted with the text. (It isn't
obvious, but all the characteristics of a section -- margins,
headers/footers, page orientation, etc. -- are stored in the section break
at the end of the section, not at the beginning. See
http://word.mvps.org/FAQs/Formatting/WorkWithSections.htm for more
enlightenment.)

For the blanks, it's usually more important to know what's immediately
*after* the blank than before it (the only exception being when the
preceding paragraph has a very large value for the Space After setting).

If the blank is followed by a hard page break, the answer is to delete the
page break. Actually, the initial template shouldn't contain any hard page
breaks, precisely because you can't tell when they'll cause problems like
this. Instead, use the paragraph settings Keep With Next and Keep Together
where necessary.

If it's a Next Page section break, either delete it by having it inside the
bookmark (if you don't need a section break there for other reasons) or
change it to Continuous.

If it's neither, put the cursor in the paragraph immediately after the
blank. Open the Task Pane and select the Reveal Formatting pane. Look for
and eliminate any of these settings from the template:
 - Page Break Before
 - Keep With Next, if the paragraphs that follow also have it so that the
whole page becomes an indivisible block
 - Space Before with a large value (in the hundreds of points), although
this would have shown up in the initial template so it's unlikely

One final comment: The line of code I showed before, using the Range of the
bookmark, accomplishes the same deletion as the two lines in your code, but
it also doesn't move the user's cursor, and if the block is off-screen the
user won't even see the deletion happening. To fit into your code, the line
would be

  ActiveDocument.Bookmarks(strBookmark).Range.Delete

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

Denise - 03 Nov 2004 13:29 GMT
>>> Hi Denise,
>>>
[quoted text clipped - 101 lines]
>
>    ActiveDocument.Bookmarks(strBookmark).Range.Delete

Hi Jay

Thanks very much for the info.  Your advice on section breaks has helped
enormously - so obvious when someone tells you!  I'm still messing about
with the blank spaces but the template is so much improved just by the
removal of the section breaks.

Thanks again

Denise Crawley
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.