A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Email Selected or Not Macro Script



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 4th 07, 09:47 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 13
Default Email Selected or Not Macro Script

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

Ads
  #2  
Old May 4th 07, 01:44 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Email Selected or Not Macro Script

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
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

  #3  
Old May 4th 07, 04:45 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 13
Default Email Selected or Not Macro Script

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

  #4  
Old May 4th 07, 05:13 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 13
Default Email Selected or Not Macro Script

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

  #5  
Old May 4th 07, 11:00 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Email Selected or Not Macro Script

Glad you caught my error in omitting Selection!

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Server-side rule with script or macro Brian Canner Outlook and VBA 1 February 12th 07 07:59 PM
"run a script" rule won't fire macro [email protected] Outlook and VBA 3 October 18th 06 07:08 AM
script/macro to send auto reply to sender ah Outlook and VBA 6 June 22nd 06 05:21 PM
multiple macro/script in 1 outlook ah Outlook and VBA 7 June 22nd 06 03:04 AM
Macro to change font of selected text in mail message? Joe HM Outlook and VBA 1 April 6th 06 07:06 PM


All times are GMT +1. The time now is 08:11 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.