Create Folders Along with ObjItem.Move ?

G

gamename

Hi,

I have a script which replaces rules in OL2003. The way I have folders
defined is like this:

Dim xxx As MAPIFolder
Set my_xxx = Inbox.Folders.Item("xxx")

' ... then after much logic to determine if this is the correct email
....

objItem.Move my_xxx


Is there any way to:
1) Create a folder if it doesn't exit
2) Avoid the Dim/Set steps?


TIA
-T
 
S

Sue Mosher [MVP-Outlook]

1) Create a folder if it doesn't exit

On Error Resume Next
Set myFolder = Inbox.Folders("My Folder")
If myFolder Is Nothing Then
Set myFolder = Inbox.Folders.Add("My Folder")
End If
2) Avoid the Dim/Set steps?

Why would you want to avoid good programming practice?

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

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

gamename

Sue said:
On Error Resume Next
Set myFolder = Inbox.Folders("My Folder")
If myFolder Is Nothing Then
Set myFolder = Inbox.Folders.Add("My Folder")
End If


Why would you want to avoid good programming practice?

So, every single possible folder needs to be pre-defined in VB?
 
S

Sue Mosher [MVP-Outlook]

No, you can Dim an object variable and instantiate it to the folder you want to move that item to. Then you later reuse the variable to move the item to a different folder.

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

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

gamename

Sue said:
No, you can Dim an object variable and instantiate it to the folder you want to move that item to. Then you later reuse the variable to move the item to a different folder.

OK. Is there an example somewhere for reference?

Thanks,
-T
 
S

Sue Mosher [MVP-Outlook]

You already had it in your earlier code snippet that you posted.

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

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

gamename

So, you're saying the way I had it defined in the original question is
correct?

-T
 
S

Sue Mosher [MVP-Outlook]

Dim xxx As MAPIFolder

Set xxx = <some expression to get the folder>

' move items to xxx

Set xxx = <some expression to get another folder>

' move items to xxx

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

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


gamename said:
So, you're saying the way I had it defined in the original question is
correct?

-T
You already had it in your earlier code snippet that you posted.

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

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


gamename said:
Sue Mosher [MVP-Outlook] wrote:
No, you can Dim an object variable and instantiate it to the folder you want to move that item to. Then you later reuse the variable to move the item to a different folder.

OK. Is there an example somewhere for reference?

Thanks,
-T
 
G

gamename

Ah, ok. Now I see what you're saying.

Thanks,
-T
Sue said:
Dim xxx As MAPIFolder

Set xxx = <some expression to get the folder>

' move items to xxx

Set xxx = <some expression to get another folder>

' move items to xxx

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

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


gamename said:
So, you're saying the way I had it defined in the original question is
correct?

-T
You already had it in your earlier code snippet that you posted.

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

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



Sue Mosher [MVP-Outlook] wrote:
No, you can Dim an object variable and instantiate it to the folder you want to move that item to. Then you later reuse the variable to move the item to a different folder.

OK. Is there an example somewhere for reference?

Thanks,
-T
 
Top