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

"Simple" macro



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 15th 06, 04:24 PM posted to microsoft.public.outlook.program_vba
donbowyer
external usenet poster
 
Posts: 12
Default "Simple" macro

I'm running MS Outlook 2003 with SP2 on Win XP home.
With a given e-mail message selected, I would like, with one click of a
custom toolbar button, to do the following:-
1. Add sender to blocked e-mail list
2. Move the e-mail to the Junk e-mail folder
I realise there are menu items for these, but I need to automate.
Unfortunately, as Outlook appears to have no Record Macro capability, I am
having difficulty writing appropriate code.
I've done the custom button and got this far with item 2:-

Sub MyJunk()
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim myDestFolder As Outlook.MAPIFolder
Set myDestFolder = Application.Explorers.Item("Junk E-mail")
myOlSel.Move myDestFolder
End Sub
It steps thru ok until the last line of code when, I get the following error:-
"Object variable or With block variable not set"
I don't know how to write code for Item for 1.
Any suggestions would be appreciated.

--
donwb
  #2  
Old May 15th 06, 10:58 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default "Simple" macro

There is no documented method to read/edit the blocked senders list in
Outlook 2003. You can still manually move them though. The problem with
your code is how you retrieve a folder. See below as an example of how to
get the root folder of a particular store (like a .pst file) by folder and
store name.

You'll also have to iterate the Selection object to move items individually:

Dim objItem As Object

For Each objItem in myOlSel
objItem.Move myDestinationFolder
Next

Sub TestGetRootFolder()
Dim objF As Outlook.MAPIFolder

Set objF = GetRootFolder("Junk E-mail", "Eric Legault")

Debug.Print objF.Name
Set objF = Nothing
End Sub

Function GetRootFolder(FolderName As String, StoreName As String) As
MAPIFolder

Dim objNS As NameSpace
Dim objRootFolder As Outlook.MAPIFolder

Set objNS = Application.GetNamespace("MAPI")
Set objRootFolder = objNS.Folders(StoreName)
Set GetRootFolder = objRootFolder.Folders(FolderName)

Set objRootFolder = Nothing
Set objNS = Nothing

End Function

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"donbowyer" wrote:

I'm running MS Outlook 2003 with SP2 on Win XP home.
With a given e-mail message selected, I would like, with one click of a
custom toolbar button, to do the following:-
1. Add sender to blocked e-mail list
2. Move the e-mail to the Junk e-mail folder
I realise there are menu items for these, but I need to automate.
Unfortunately, as Outlook appears to have no Record Macro capability, I am
having difficulty writing appropriate code.
I've done the custom button and got this far with item 2:-

Sub MyJunk()
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim myDestFolder As Outlook.MAPIFolder
Set myDestFolder = Application.Explorers.Item("Junk E-mail")
myOlSel.Move myDestFolder
End Sub
It steps thru ok until the last line of code when, I get the following error:-
"Object variable or With block variable not set"
I don't know how to write code for Item for 1.
Any suggestions would be appreciated.

--
donwb

 




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
Macro to add calendar items from "birthday" field of imported cont Peter K. Outlook and VBA 2 April 6th 06 03:32 PM
when using a Excel csv file the show time "free" not "busy" greg Outlook - Calandaring 1 March 27th 06 06:24 AM
Outlook express address book, "tools", "option" feature missing f. Brad Outlook - Using Contacts 3 March 12th 06 12:46 AM
Only when i forward emails with attachements "550 relaying mail to" [domain] "is not allowed" Alchemy Outlook - General Queries 4 March 9th 06 12:47 AM
macro for "from" field Roann Outlook and VBA 1 January 30th 06 07:41 AM


All times are GMT +1. The time now is 12:38 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.