Create Folders Along with ObjItem.Move ?

  • Thread starter Thread starter gamename
  • Start date Start date
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
 
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
 
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?
 
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
 
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
 
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
 
Back
Top