Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading bookmarked text from a word doc to vba

Status
Not open for further replies.

Grieg

Technical User
Sep 13, 2002
20
GB
Hi,

I have a word template where I want the code behind it to import a section of bookmarked text from another word document and load it into a string\form property.

I can't use the open the document as a text stream as its a word doc - could anyone point me in the right direction.

Any help greatly appreciated,

Grieg
 
Hi,

You need to have both documents open.

Then some code like this...
Code:
Private Sub UserForm_Click()
    Set doc1 = Documents("doc1.doc")
    Set doc2 = Documents("doc2.doc")
    
    UserForm1.TextBox1.Text = doc2.Bookmarks("bm1").Range.Text
End Sub
Hope this helps  :-)

Skip,
Skip@TheOfficeExperts.com
[URL unfurl="true"]www.TheOfficeExperts.com[/URL]
 
Hiya skip,

Problem was that I didn't want to open an active version of the document I was taking the text from so the user would only have the one visible document. In the end I solved it using the following code (included it in case any one ever has the same query!);

Dim objST As Object, strDocPath As String
strDocPath = x:\xxxxx\xxxxx.doc
Set objST = CreateObject(Class:="Word.Document")
Set objST = GetObject((strDocPath), "word.document")
'set controltipttext to first 150 chars of bookmarked text
Form.Label.ControlTipText = Left((objST.Bookmarks(pubStrKrBm1).Range), 150)

Thanks for your reply,
Grieg.
 
You're right. Sorry for not making this clearer.

Grieg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top