How to delete text between two bookmarks

J

Jason

Hi, I am a relatively experienced Excel VBA user, but very new to Word VBA.

How can I delete all text between two bookmarks, leaving the bookmarks
intact? The first bookmark is at the end of a paragraph (eoFirstPara), and
the second bookmark is at the beginning of a different paragraph, toward the
end of the document (boLastPara).

TIA for any insight.

Jason
 
G

Greg Maxey

Jason,

Not tested, but something like:
Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Content
oRng.Start = ActiveDocument.Bookmarks("Name1").Range.End
oRng.End = ActiveDocument.Bookmarks("Name2").Range.Start
oRng.Delete
End Sub
 
J

Jezebel

Simpler still --

With ActiveDocument
.Range(.Bookmarks("Name1").Range.End,
..Bookmarks("Name2").Range.Start).Delete
End With
 
J

Jason

Thanks very much to both of you. :)

I have a couple more issues if you wouldn't mind addressing them in this
thread:

1. I have a couple of form fields that self-populate based on entries into
other form fields (one is a form field drop-down list and the other is a
fill-in). These are populated before runnign some procedures (code). Once
these procedures are run, the form fields revert back to their "default"
text. Is there a way to keep them from reverting back (i.e. holding their
values)?

2. After protecting the document, a pop-up box (looks similar to a
multi-line input box) appears, but it does not have any kind of description
of its purpose. What is causing this box, and how do I get rid of it? To see
what the box looks like, here is a link to the image:
http://www.j-and-r-williams.com/1.jpg

Thanks again!

Jason
 
J

Jezebel

1. I have a couple of form fields that self-populate based on entries into
other form fields (one is a form field drop-down list and the other is a
fill-in). These are populated before runnign some procedures (code). Once
these procedures are run, the form fields revert back to their "default"
text. Is there a way to keep them from reverting back (i.e. holding their
values)?

Have a look at the Protect statement in the code: it should include the
NoReset argument.

2. After protecting the document, a pop-up box (looks similar to a
multi-line input box) appears, but it does not have any kind of
description
of its purpose. What is causing this box, and how do I get rid of it? To
see
what the box looks like, here is a link to the image:
http://www.j-and-r-williams.com/1.jpg

It's an InputBox. Somewhere in your code is an InputBox statement. You need
to ask the programmer why they put it there.
 
J

Jason

Well, I am the programmer, and there is no InputBox statement in my code.
However, I believe what was triggering it is I had the "calculate on exit"
box checked on a couple of the form fields. After I unchecked them, no more
input box.

Thanks again.

Jason
 

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