I finally found the solution!!!
it's VERY tricky, especially for someone like me who is relatively new to VBA programming... The problem was that the embedded object had no name, so when I ran the macro I got "1004" error msg. What I did was the following:
Dim XL As Excel.Application
Public Sub Tarif1()
Dim MyTask As Task
On Error GoTo NotMSWord
If Right(ActiveWorkbook.FullName, 3) = "doc" Then
On Error GoTo 0
Cells.Select
Selection.Copy
Set XL = New Excel.Application
XL.Visible = True
XL.Workbooks.Add
XL.ActiveSheet.Paste
XL.AddIns("Tarification"
.Installed = True
Word.Application.DisplayAlerts = wdAlertsNone
XL.Application.DisplayAlerts = False
For Each MyTask In Tasks
If InStr(MyTask.Name, "Microsoft Excel"
> 0 Then
MyTask.Activate
End If
Next MyTask
TarifPath = XL.AddIns("Tarification"
.FullName
XL.Workbooks.Open TarifPath
For Each MyTask In Tasks
If InStr(MyTask.Name, "Microsoft Word"
> 0 Then
XL.Run ("tarif.xla!CloseWord"
Exit Sub
End If
Next MyTask
End If
NotMSWord:
Application.DisplayAlerts = False
ChDir "G:\"
If Err.Number = 91 Then
'=> error
Else
Filename = ActiveWorkbook.FullName
If Filename = "" Then
'=>error
Else
ActiveWorkbook.SaveAs Filename:="G:\tarif.xls", FileFormat:=xlNormal, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
End If
End If
Application.DisplayAlerts = True
End Sub
Sub CloseWord()
Tarif1
If Tasks.Exists("Microsoft Word"
Then
With Tasks("Microsoft Word"
.Application.DisplayAlerts = wdAlertsNone
.Activate
.Close
End With
End If
End Sub
In fact, I open Excel but cannot run my macro yet since I am still in Word!!! So what I did was to open a new excel workbook, paste in whatever was in the embeded object, then open the addin where my macro is, and run another macro of this addin that closes word and runs the macro I want. That way I am no longer in word and I can run excel!!!