Execute macro from word button

A

Alex St-Pierre

Hi, I have a macro which execute a mailmerge and modify the document beafter.
I would like to add a macro to Excel that will close excel, open word and
execute the word macro. Does anyone have already done something like that ?
(if the excel workbook close, it stop the macro ?)
 
H

Helmut Weber

Hi Alex,

after closing Excel there is no way,
to continue an Excel macro, IMHO.

Or close the Excel workbook, which contains the macro.

You may have an Excel macro,
which starts Word,
opens a doc or creates a doc,
does a mailmerge etc.
and then closes Excel.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

Alex St-Pierre

Hi Helmut,
Since the main excel workbook from which Macro is executed open a word
mailmerge that is linked to the main document, it ask to close the excel
workbook to be able to set DDE connexion. If I am able to set DDE with
activeworkbook without closing it, it will work good. Do you know how ?

I have pasted here some code I tried:
Sub Execution_MailMerge_From_Excel()
On Error Resume Next
Set WdApp = GetObject("", "Word.Application")
If WdApp Is Nothing Then
Set WdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Dim WbName as string
WbName = ActiveWorkbook.Name
Set oWordDoc = oWord.Open("C:\mailmerge.doc") 'This ask to close excel..??
Maybe, can I set condition to say: I don't want to open the excel source file
as you can click when you open only "mailmerge.doc" ?
ActiveDocument.MailMerge.OpenDataSource Name:= _
WbName, ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="merge", SQLStatement:="", SQLStatement1:="", SubType:= _
wdMergeSubTypeOther
oWord.macro1 'will execute the first Macro (In excel, I have to put the
Macro in ThisWorkbook to work: is there the same thing in word ?)

End Sub()
 

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