Word VBA - Documents.Open

M

mr tom

To open a specified document, one can use:

Sub OpenDocument()
Documents.Open FileName:="C:\MyFolder\Sample.doc"
End Sub

If I have a bookmark (name:"CustomerName") which will of course vary, how
can I use the Documents.Open command to open e.g.
c:\customers\&"CustomerName"&.doc?

Any thoughts?

Many thanks,

Tom.
 
J

Jonathan West

mr tom said:
To open a specified document, one can use:

Sub OpenDocument()
Documents.Open FileName:="C:\MyFolder\Sample.doc"
End Sub

If I have a bookmark (name:"CustomerName") which will of course vary, how
can I use the Documents.Open command to open e.g.
c:\customers\&"CustomerName"&.doc?

Any thoughts?

Many thanks,

Tom.

I'm not sure where the bookmark comes into this. Are you saying that the
bookmark marks text in a document that you already have open, and you want
that text to form the filename of the additional document to be opened?

If so, then you need something like this

Sub OpenDocument()
Dim strFilename as String
strFileName = ActiveDocument.Bookmarks("CustomerName").Range.Text
Documents.Open FileName:="C:\MyFolder\" & strFileName & ".doc"
End Sub


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
M

mr tom

That's fantastic. Thank you.

Jonathan West said:
I'm not sure where the bookmark comes into this. Are you saying that the
bookmark marks text in a document that you already have open, and you want
that text to form the filename of the additional document to be opened?

If so, then you need something like this

Sub OpenDocument()
Dim strFilename as String
strFileName = ActiveDocument.Bookmarks("CustomerName").Range.Text
Documents.Open FileName:="C:\MyFolder\" & strFileName & ".doc"
End Sub


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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