A section that appears or disappears

B

bazzlad

Hey all,
This sounds so simple, but is complete doing my head in!

I have a word VBA file, that on open, a form pops up and the user
fills in the details.
It then populates 2 files with said information, and copys important
information to the clipboard - thus saving a lot of time.

I'm using textboxes in tables on the word file and textboxes on the
userform.

However, there is a section that may not apply to everybody, and I
don't want the user to have to delete it if it doesn't apply - I'd
like my program to do that for him. If this section isn't applicable
to the specific client, I'd like to be able to remove it with a check
box - and for the rest of the file to "move up" as to not leave a
massive space in the document.


Anyone know this, it sounds simple, but I can't figure it out!

Cheers,
Rich
 
R

Rob

When you say "section", do you mean that you have separated this area from
the rest of the document using section breaks, or do you just mean that
certain text, praragraphs, etc, comprise this section? The solution would be
different in each case.

One solution would be to select the text to be deleted and put a bookmark
around it. Name it bkDelSection, for example, then delete the bookmark in the
code if needed. You would do so like this:
Selection.GoTo What:=wdGoToBookmark, Name:="bkDelSection"
Selection.Delete Unit:=wdCharacter, Count:=1

If there is any chance the bookmark may already be deleted when the code
runs then you'll want to check so it doesn't error, like this:
If ActiveDocument.Bookmarks.Exists("bkDelSection") Then
ActiveDocument.Bookmarks("bkDelSection").Select
Selection.Delete
End If


If you already have it sectioned off by section breaks, and you know which
section it is, then you could do this (change the number to the section you
need to nuke):
ActiveDocument.Sections(1).Range.Delete
 

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