How to insert a bookmark with a range

W

Word.user

I want to insert a bookmark with a range of lets say 3,4 blank lines, when I
open a document. And the bookmark text as null.
I worte the following code, but it does not work cause line 2 expects an
object and I dont have any.
I am going to open a blank document and insert a bookmark with 4 blank lines.

How can I acheive this....
[



]

My Code:
Set BMRange = ActiveDocument.Bookmarks("start").Range
ActiveDocument.Bookmarks("start").Range.Text = Chr(13) & Chr(13)
ActiveDocument.Bookmarks("start").Range.Text = " "
ActiveDocument.Bookmarks.Add "start", BMRange
 
D

Doug Robbins - Word MVP

Dim bmrange As Range
With ActiveDocument
.Range.InsertBefore vbCr & vbCr & vbCr & vbCr
Set bmrange = .Range
bmrange.End = bmrange.start + 5
.Bookmarks.Add "Start", bmrange
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
W

Word.user

Thanks a lot

Doug Robbins - Word MVP said:
Dim bmrange As Range
With ActiveDocument
.Range.InsertBefore vbCr & vbCr & vbCr & vbCr
Set bmrange = .Range
bmrange.End = bmrange.start + 5
.Bookmarks.Add "Start", bmrange
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Word.user said:
I want to insert a bookmark with a range of lets say 3,4 blank lines, when
I
open a document. And the bookmark text as null.
I worte the following code, but it does not work cause line 2 expects an
object and I dont have any.
I am going to open a blank document and insert a bookmark with 4 blank
lines.

How can I acheive this....
[



]

My Code:
Set BMRange = ActiveDocument.Bookmarks("start").Range
ActiveDocument.Bookmarks("start").Range.Text = Chr(13) & Chr(13)
ActiveDocument.Bookmarks("start").Range.Text = " "
ActiveDocument.Bookmarks.Add "start", BMRange
 
W

Word.user

Sorry about this
The beginning of bookmark falls under a protected section, so when I insert
these lines (vbCr & vbCr & vbCr & vbCr), it is increasing the protected
section nad not allowing me to edit, is it possible to just go 2 lines down
without vbCr and then do vbCr, so I can skip the protected section and get
into unprotected section
Thanks once again, and appreciate your help

Word.user said:
Thanks a lot

Doug Robbins - Word MVP said:
Dim bmrange As Range
With ActiveDocument
.Range.InsertBefore vbCr & vbCr & vbCr & vbCr
Set bmrange = .Range
bmrange.End = bmrange.start + 5
.Bookmarks.Add "Start", bmrange
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Word.user said:
I want to insert a bookmark with a range of lets say 3,4 blank lines, when
I
open a document. And the bookmark text as null.
I worte the following code, but it does not work cause line 2 expects an
object and I dont have any.
I am going to open a blank document and insert a bookmark with 4 blank
lines.

How can I acheive this....
[



]

My Code:
Set BMRange = ActiveDocument.Bookmarks("start").Range
ActiveDocument.Bookmarks("start").Range.Text = Chr(13) & Chr(13)
ActiveDocument.Bookmarks("start").Range.Text = " "
ActiveDocument.Bookmarks.Add "start", BMRange
 
D

Doug Robbins - Word MVP

Use

Dim bmrange As Range
Set bmrange = Selection.Range
bmrange.InsertBefore vbCr & vbCr & vbCr & vbCr
ActiveDocument.Bookmarks.Add "Start", bmrange


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Word.user said:
Sorry about this
The beginning of bookmark falls under a protected section, so when I
insert
these lines (vbCr & vbCr & vbCr & vbCr), it is increasing the protected
section nad not allowing me to edit, is it possible to just go 2 lines
down
without vbCr and then do vbCr, so I can skip the protected section and get
into unprotected section
Thanks once again, and appreciate your help

Word.user said:
Thanks a lot

Doug Robbins - Word MVP said:
Dim bmrange As Range
With ActiveDocument
.Range.InsertBefore vbCr & vbCr & vbCr & vbCr
Set bmrange = .Range
bmrange.End = bmrange.start + 5
.Bookmarks.Add "Start", bmrange
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I want to insert a bookmark with a range of lets say 3,4 blank lines,
when
I
open a document. And the bookmark text as null.
I worte the following code, but it does not work cause line 2 expects
an
object and I dont have any.
I am going to open a blank document and insert a bookmark with 4
blank
lines.

How can I acheive this....
[



]

My Code:
Set BMRange = ActiveDocument.Bookmarks("start").Range
ActiveDocument.Bookmarks("start").Range.Text = Chr(13) & Chr(13)
ActiveDocument.Bookmarks("start").Range.Text = " "
ActiveDocument.Bookmarks.Add "start", BMRange
 

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