View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Opening word from within xls

Try something like this

Sub test()
Dim sLink As String
Dim oWd As Object ' As Word
Dim oDoc As Object ' As Document

sLink = Range("C4").Hyperlinks(1).Address ' path & .doc filename

On Error Resume Next
' attempt to find a running instance of Word
Set oWd = GetObject(, "word.application")
On Error GoTo 0

If oWd Is Nothing Then
' start a new instance of Word
Set oWd = CreateObject("word.application")
End If
oWd.Visible = True
Set oDoc = oWd.documents.Open(sLink)

End Sub


Maybe you could record a macro in Word to do the rest of your mailmerge,
then adapt it to include in the above.

If you set a reference to Word in Tools (on the main VBE menu bar) you can
change As Object to As Word & Document to get Word's VBA intellisense.

Regards,
Peter T

"AB" wrote in message
...
Hi,
I'm trying to launch .doc from within .xls using FollowHyperlink
method (as i need it to go via dde and simple open method doesn't
work).

The .xls contains invoicing data wile the .doc is MailMerge (to create
the invoice) based on that same .xls (i'm launching the .doc from) via
dde. As a result it stalls (says that can't access) because:

- the dde connection in the .doc MM is trying to connect to the .xls
that stores the invoicing data

- since i'm launching the .doc from the same .xls where the invoicing
data are stored - the code 'locks' the .xls (since the code is still
kind of running as it waits till the .doc opens) but the .doc can't
open since it can't reach the locked .xls file - a vicious cycle...

Any ideas how to have the .xls 'unlock' for the time while the .doc MM
is opening?
Any help would be greatly appreciated.