kosenrufu
asked on
How do I modify this VBA to close Outlook?
Public Sub OutlookStart()
On Error Resume Next
Dim objOL As Object
'check if Outlook is running
Set objOL = GetObject(, "Outlook.Application")
'on error start Outlook
If Err.Number <> 0 Then '
Err.Clear
'**Open Outlook and select profile
Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex e" & " /profile leanretail", vbMinimizedFocus
'Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex e", vbMinimizedFocus
DoEvents
End If
Set objOL = Nothing
End Sub
Thanks
On Error Resume Next
Dim objOL As Object
'check if Outlook is running
Set objOL = GetObject(, "Outlook.Application")
'on error start Outlook
If Err.Number <> 0 Then '
Err.Clear
'**Open Outlook and select profile
Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex
'Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex
DoEvents
End If
Set objOL = Nothing
End Sub
Thanks
ASKER
It is opened using Shell
Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex e" & " /profile leanretail", vbMinimizedFocus
Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex
I see that.
What are you doing with Outlook?
Is this code just meant to open it and nothing else?
What are you doing with Outlook?
Is this code just meant to open it and nothing else?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
imnorie:
I tried using your code but it did not work
I tried using your code but it did not work
Did you change the caption?
You wouldn't need this code if you opened Outlook with CreateObject instead of Shell.
If you did that you could close it with the first code I posted.
You wouldn't need this code if you opened Outlook with CreateObject instead of Shell.
If you did that you could close it with the first code I posted.
As imnorie said:
What are you doing with Outlook after you open it with your Shell command?
What are you doing with Outlook after you open it with your Shell command?
ASKER
I am sending email using VBA code
If that's what you are doing why are you using Shell?
Opening Outlook with Shell doesn't give you any control in your code to do anything with it.
Try using CreateObject("Outlook.Appl ication") instead.
Opening Outlook with Shell doesn't give you any control in your code to do anything with it.
Try using CreateObject("Outlook.Appl
On Error Resume Next
Dim objOL As Object
'check if Outlook is running
Set objOL = GetObject(, "Outlook.Application")
'on error start Outlook
If Err.Number <> 0 Then '
Err.Clear
Set objOL = CreateObject("Outlook.Application")
End If
' use code to create and send your email with Outlook
' close Outlook
objOL.Quit
Set objOL = Nothing
ASKER
I ma using Outlook profile. How would I select a profile with VBA?
Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex e" & " /profile leanretail", vbMinimizedFocus
Shell "C:\Program Files\Microsoft Office\Office12\outlook.ex
What are you using the profile for?
And again - why are you using the Shell command to open Outlook if you're just sending emails? Does the user need to interact with OUtlook in some way OTHER than sending an email? If you use SendObject, and you set the last parameter to True (see the link above), then Access will open your email message, and the user can interact with it.
Open in new window
If it's been opened using Shell then you'll need something else.