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 / March 2007

Tip: Looking for answers? Try searching our database.

A section that appears or disappears

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bazzlad@gmail.com - 15 Mar 2007 14:05 GMT
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
Rob - 16 Mar 2007 14:35 GMT
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
 
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.