Word from Excel

S

Simon

I'm using excel to open a preformatted word document from
a hyperlink and adding data from the excel record using
bookmarks. I want the word document to be saved according
to the bookmark value. I can't seem to be able to get the
last bit to work. Also everynow and then the code stops
because it can't find the bookmark and the only apparent
round this to get it working again is by logging off and
on again. The code I'm using is

Dim WordObj As Object
Set WordObj = CreateObject("Word.Basic")
Selection.Hyperlinks(1).Follow NewWindow:=True,
AddHistory:=True
Application.WindowState = xlMaximized
With WordObj
.EditBookmark "txtNo", 0, 0, 0, 1
.Insert txtNo.Value
End With

Any suggestions much appreciated
 
B

Bob Phillips

Not tested, but try to trap it

Dim WordObj As Object

On Error Resum Next
Set WordObj = CreateObject("Word.Basic")
On Error Goto 0
If WordObj Is Nothing Then
Msgbox "Bookmark not found"
Else
Selection.Hyperlinks(1).Follow NewWindow:=True,
AddHistory:=True
Application.WindowState = xlMaximized
With WordObj
.EditBookmark "txtNo", 0, 0, 0, 1
.Insert txtNo.Value
End With
End If
 

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