vodkasoda
02-05-2013, 11:53 AM
I have a button in a Word Document that executes the following code ... the first three steps work, the Word document is saved, it is E:Mailed and it is closed, but that leaves Word still running ... now do I close Word ?!?
Sub myButtonMacro(control As IRibbonControl)
ActiveDocument.Save
SendToChris
ActiveDocument.Close
' The Word Document has been sent & has been closed, but Word itself is still open ...
End Sub
Sub SendToChris()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "mytest@gmail.com"
.Subject = "NewsLetter " + ActiveDocument.Name
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
Sub myButtonMacro(control As IRibbonControl)
ActiveDocument.Save
SendToChris
ActiveDocument.Close
' The Word Document has been sent & has been closed, but Word itself is still open ...
End Sub
Sub SendToChris()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "mytest@gmail.com"
.Subject = "NewsLetter " + ActiveDocument.Name
'Add the document as an attachment, you can use the .displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
DisplayName:="Document as attachment"
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub