Email Selected or Not Macro Script

  • Thread starter Thread starter freeman642
  • Start date Start date
F

freeman642

I have written a small application using ActiveExplorer, the thing is
if an email is not selected I still want to run the script, how do I
say if an email is not selected then still run the script. I guess I
am looking at an if statement, but when do I check it? I am guessing
it is at the ActiveExplorer set up, because if the is not one when
this runs it closes it with an error message. The script below is
what
I have tried if it hasn got an email it puts up a messagebox.

Dim OlApp As New Outlook.Application
Dim OlExp As Outlook.Explorer
Dim OlSel As Outlook.Selection
Dim OlItem As Outlook.MailItem


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
If olApp.ActiveExplorer IsNot nothing then
Set OlExp = OlApp.ActiveExplorer
Set OlSel = OlExp.Selection
Set OlItem = OlSel.Item(1)
Else
Msgbox("No email selected")
End if


.......


Any ideas gratefully recieved I am pulling my hair out.


Thanks John
 
If Not olApp.ActiveExplorer Is Nothing then
If olApp.ActiveExplorer.Count = 0 Then
MsgBox "No item is selected"
End If
End IF


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Thanks for your response Sue,

Dim OlApp As New Outlook.Application
Dim OlExp As Outlook.Explorer
Dim OlSel As Outlook.Selection
Dim OlItem As Outlook.MailItem


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set OlExp = OlApp.ActiveExplorer
If not olApp.ActiveExplorer Is nothing then
If olApp.ActiveExplorer.Selection.Count = 0 Then
MsgBox "No item is selected"
Else
Set OlSel = OlExp.Selection
Set OlItem = OlSel.Item(1)
End if
End If

When I try the Count it says Runtime error -1249771511 (b5820009) "the
Explorer has been closed and cannot be used for further operations."

Thanks John
 
Sorted, had my google site in my email and selected that folder would
not work in any way, but that does matter selected any other folder
other than that and email and it works a treat.

Thank you for your help. I am now not bald which is a good thing.

Thanks again. John
 
Glad you caught my error in omitting Selection!

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top