Reveiw the VB Code for Macro

  • Thread starter Thread starter Tye Davis
  • Start date Start date
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
 
1) The Namespace object has no Folder property. To get a non-default folder,
you need to walk the folder hierarchy using the Folders collections or use a
function that does that for you. See
http://www.outlookcode.com/d/code/getfolder.htm

2) The Items collection has no Forward method. Each individual item in the
Items collection, however, does.
 
I have been having no success at all. When I select
Macro, it wants me to create another and it doesn't even
list the one I created with the function below. I modified
and used the following code I found at outlookcode.com and
nothing happens:

Function GetFolder(Inbox\Company Project\Project1)
' folder path needs to be something like
' "Inbox\Company Project\Project1"
Dim aFolders
Dim fldr
Dim i
Dim objNS

On Error Resume Next
strFolderPath = Replace(FolderPath, "/", "\")
aFolders = Split(FolderPath, "\")

'get the Outlook objects
' use intrinsic Application object in form script
Set objNS = Application.GetNamespace("MAPI")

'set the root folder
Set fldr = objNS.Folders(aFolders(0))

'loop through the array to get the subfolder
'loop is skipped when there is only one element in the
array
For i = 1 To UBound(aFolders)
Set fldr = fldr.Folders(aFolders(i))
'check for errors
If Err <> 0 Then Exit Function
Next
Set GetFolder = fldr

' dereference objects
Set objNS = Nothing
End Function
 
I don't know what you mean when you say "I select macro." Did you declare
your procedure with the Sub or Function keyword?

You are not using the GetFolder() function correctly. The argument is a
variable representing the path of an argument. Like any function, you call
it in your procedure code, passing the specific value you want that variable
to have. Strings need to be in quotation marks. Also, the folder path for
GetFolder() must be the complete path from the top level of the information
store where the folder resides. I can't tell from your post whether this is
an Exchange mailbox or a .pst file, so you'll have to adjust accordingly:

Function GetFolder(strFolderPath)
' the function code goes here
End Function

Sub MyProcedure()
Set myFolder = GetFolder("PersonalFolders\Inbox\Company
Project\Project1")
' your code to do stuff with myFolder goes here
End Sub

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top