Insert file contents within an enclosed bookmark.

R

Raj

Hi Guys/Dolls

How do I insert the contents of a file between an enclosed bookmark?

some code which I found at
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm

Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub

but this deals with text - so how do I insert contents of a file.

Any help would be appreciated.

Raj
 
D

Dave Lett

Hi Raj,

You can use something like the following:

Set oRng = ActiveDocument.Bookmarks("Test").Range
oRng.Select
Selection.Range.InsertFile FileName:="C:\Test.doc"

HTH,
Dave
 
R

Raj

Hi Dave
This worked but it changed my bookmark from an enclosed bookmark to a
placeholder bookmark. How do I do it so that it stays as original.
Example

[enclosed bookmark contents]

After implementation of your code snippet it becomes as follows:-

|file contents

where | is the placeholder bookmark
what I really want besides winning the lottery is after running your code
snippet it should be

[file contents]

where [ and ] depict the start and end of the enclosed bookmark.

Thanks for your help again.

Raj
 
R

Russ

Raj,
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
Hi Dave
This worked but it changed my bookmark from an enclosed bookmark to a
placeholder bookmark. How do I do it so that it stays as original.
Example

[enclosed bookmark contents]

After implementation of your code snippet it becomes as follows:-

|file contents

where | is the placeholder bookmark
what I really want besides winning the lottery is after running your code
snippet it should be

[file contents]

where [ and ] depict the start and end of the enclosed bookmark.

Thanks for your help again.

Raj




Dave Lett said:
Hi Raj,

You can use something like the following:

Set oRng = ActiveDocument.Bookmarks("Test").Range
oRng.Select
Selection.Range.InsertFile FileName:="C:\Test.doc"

HTH,
Dave
 
R

Russ

Raj,
I just noticed that you were already at that link. But you should be able to
combine what that link told you, with what Dave told you. Duplicate the
bookmark as a range, insert file at that range, then re-establish bookmark
at that range.
Raj,
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
Hi Dave
This worked but it changed my bookmark from an enclosed bookmark to a
placeholder bookmark. How do I do it so that it stays as original.
Example

[enclosed bookmark contents]

After implementation of your code snippet it becomes as follows:-

|file contents

where | is the placeholder bookmark
what I really want besides winning the lottery is after running your code
snippet it should be

[file contents]

where [ and ] depict the start and end of the enclosed bookmark.

Thanks for your help again.

Raj




Dave Lett said:
Hi Raj,

You can use something like the following:

Set oRng = ActiveDocument.Bookmarks("Test").Range
oRng.Select
Selection.Range.InsertFile FileName:="C:\Test.doc"

HTH,
Dave

Hi Guys/Dolls

How do I insert the contents of a file between an enclosed bookmark?

some code which I found at
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm

Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub

but this deals with text - so how do I insert contents of a file.

Any help would be appreciated.

Raj
 

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