Review My VB Code for Macro - Outlook

T

Tye Davis

TO: Sue Mosher or anyone else who can assist me

Senerio: I am setting up a macro Ctl Alt+L to forward to
John Doe all the items found in Folders named Project1,
Project2, Project3.

Outlook Setup is:
Inbox Folder
Company Project
Project1
Project2
Project3
Company Marketing
Company Documents
Journals
Notes
Outbox
Send
Tasks

Using the information Sue supplied, I came up with this:

Set myOlApp = CreateObject ("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace ("MAPI")
Set myFolder = myNameSpace.Project1Folder
(olFolderProject1)
Set myForward = myFolder.Items.Forward
myForward.Recipients.Add "John Davis"
myForward.Send

Set myFolder = myNameSpace.Project2Folder
(olFolderProject2)
Set myForward = myFolder.Items.Forward
myForward.Recipients.Add "Dan Davis"
myForward.Send

Set myFolder = myNameSpace.Project2Folder
(olFolderProject2)
Set myForward = myFolder.Items.Forward
myForward.Recipients.Add "Charles Davis"
myForward.Send

Is this correct? Do I set the macro on the Company Project
Folder or the first project folder?

Thanks in advance!
Tye Davis


Subject: Re: Message Not Posting
From: "Sue Mosher [MVP-Outlook]"
<[email protected]> Sent: 10/4/2004
12:14:31 PM


Outlook code doesn't work that way. (Perhaps you're more
accustomed to
working with recorded Word macros?) In Outlook, the pseudo
code would be
something like:

Get starting folder
(Application.ActiveExplorer.CurrentFolder)
Get first subfolder (MAPIFolder.Folders)
Get the first item in the subfolder (MapiFolder.Items)
Copy the item to the another folder (Copy, Move)
Keep information from the item for later use (Body,
To, Subject, etc.)
Repeat for all other items in the folder
Create a message with the information kept for later
use
(Application.CreateItem)
Send the message (MailItem.Send)
Repeat for the other subfolders

You will need to learn the Outlook objects that allow you
to perform these
tasks. I've listed the ones that are most relevant, and
you can get sample
code for virtually all of them in Outlook VBA Help.

Also, your Outlook version will affect your options for
sending a message.

If you want to learn Outlook VBA, these web pages should
help you get
started:

http://www.winnetmag.com/Articles/Index.cfm?
ArticleID=21522&pg=1
http://www.outlookcode.com/d/vb.htm

Once you've tried a couple of things,
 
K

Ken Slovak - [MVP - Outlook]

There is no myNameSpace.Project1Folder method or property.

If according to your folder tree those folders are below Inbox you'd do
something like this:

Dim oCompanyProject As Outlook.MAPIFolder
Dim oProject As Outlook.MAPIFolder

Set myOlApp = CreateObject ("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace ("MAPI")
Set oCompanyProject = myNameSpace. _
GetDefaultFolder(olFolderInbox).Folders("Company Project")
Set oProject = oCompanyProject.Folders("Project1")
'now you have Project1 and can work with it




Tye Davis said:
TO: Sue Mosher or anyone else who can assist me

Senerio: I am setting up a macro Ctl Alt+L to forward to
John Doe all the items found in Folders named Project1,
Project2, Project3.

Outlook Setup is:
Inbox Folder
Company Project
Project1
Project2
Project3
Company Marketing
Company Documents
Journals
Notes
Outbox
Send
Tasks

Using the information Sue supplied, I came up with this:

Set myOlApp = CreateObject ("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace ("MAPI")
Set myFolder = myNameSpace.Project1Folder
(olFolderProject1)
Set myForward = myFolder.Items.Forward
myForward.Recipients.Add "John Davis"
myForward.Send

Set myFolder = myNameSpace.Project2Folder
(olFolderProject2)
Set myForward = myFolder.Items.Forward
myForward.Recipients.Add "Dan Davis"
myForward.Send

Set myFolder = myNameSpace.Project2Folder
(olFolderProject2)
Set myForward = myFolder.Items.Forward
myForward.Recipients.Add "Charles Davis"
myForward.Send

Is this correct? Do I set the macro on the Company Project
Folder or the first project folder?

Thanks in advance!
Tye Davis


Subject: Re: Message Not Posting
From: "Sue Mosher [MVP-Outlook]"
<[email protected]> Sent: 10/4/2004
12:14:31 PM


Outlook code doesn't work that way. (Perhaps you're more
accustomed to
working with recorded Word macros?) In Outlook, the pseudo
code would be
something like:

Get starting folder
(Application.ActiveExplorer.CurrentFolder)
Get first subfolder (MAPIFolder.Folders)
Get the first item in the subfolder (MapiFolder.Items)
Copy the item to the another folder (Copy, Move)
Keep information from the item for later use (Body,
To, Subject, etc.)
Repeat for all other items in the folder
Create a message with the information kept for later
use
(Application.CreateItem)
Send the message (MailItem.Send)
Repeat for the other subfolders

You will need to learn the Outlook objects that allow you
to perform these
tasks. I've listed the ones that are most relevant, and
you can get sample
code for virtually all of them in Outlook VBA Help.

Also, your Outlook version will affect your options for
sending a message.

If you want to learn Outlook VBA, these web pages should
help you get
started:

http://www.winnetmag.com/Articles/Index.cfm?
ArticleID=21522&pg=1
http://www.outlookcode.com/d/vb.htm

Once you've tried a couple of things,
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top