move items

A

Amir Atary

Hello to all :)

I need help regarding writing a macro.

I would the follow senario to happen: when highlighting an email under
inbox i want to move it to inbox folder under personal folder (pst).

Any help will be appriciated.

Thank you very much :)
Amir
 
G

Guest

Hi Amir. Try this macro:

Sub MoveSelectedEmailToInbox()
On Error GoTo EH:

Dim objMessage As Object
Dim objNS As NameSpace, objInbox As MAPIFolder
Dim intX As Integer

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

For intX = Application.ActiveExplorer.Selection.Count To 1 Step -1
Set objMessage = Application.ActiveExplorer.Selection.Item(intX)
objMessage.Move objInbox
Next

Set objMessage = Nothing
Set objInbox = Nothing
Set objNS = Nothing

EH:
If Err.Number <> 0 Then
Stop
End If
End Sub

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
Collaborative Innovations
-> Try Picture Attachments Wizard For Microsoft Outlook <-
Web: http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault
 
A

Amir Atary

thank you.
I have 2 personal folder.
How the macro will know to which personal folder to address?

Regards
Amir :)

Hi Amir. Try this macro:

Sub MoveSelectedEmailToInbox()
On Error GoTo EH:

Dim objMessage As Object
Dim objNS As NameSpace, objInbox As MAPIFolder
Dim intX As Integer

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

For intX = Application.ActiveExplorer.Selection.Count To 1 Step -1
Set objMessage = Application.ActiveExplorer.Selection.Item(intX)
objMessage.Move objInbox
Next

Set objMessage = Nothing
Set objInbox = Nothing
Set objNS = Nothing

EH:
If Err.Number <> 0 Then
Stop
End If
End Sub

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
Collaborative Innovations
-> Try Picture Attachments Wizard For Microsoft Outlook <-
Web: http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault


Amir Atary said:
Hello to all :)

I need help regarding writing a macro.

I would the follow senario to happen: when highlighting an email under
inbox i want to move it to inbox folder under personal folder (pst).

Any help will be appriciated.

Thank you very much :)
Amir
 
G

Guest

The NameSpace object has each Personal Folders File as a top-level folder in
it's Folders collection. So you'd access it by name:

Set objPST1Folders = objNS.Folders("My 1st PST")
Set objPST2Folders = objNS.Folders("My 2nd PST")

Then you "walk" the folders collection to get at nested folders:

Set objFolder1 = objPST1Folders.Folders("SubFolder1")
Set objFolder2 = objFolder1.Folders("SubFolderOfSubFolder1")

The GetDefaultFolder method returns folders from the default .pst.

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
Collaborative Innovations
-> Try Picture Attachments Wizard For Microsoft Outlook <-
Web: http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault


Amir Atary said:
thank you.
I have 2 personal folder.
How the macro will know to which personal folder to address?

Regards
Amir :)

Hi Amir. Try this macro:

Sub MoveSelectedEmailToInbox()
On Error GoTo EH:

Dim objMessage As Object
Dim objNS As NameSpace, objInbox As MAPIFolder
Dim intX As Integer

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

For intX = Application.ActiveExplorer.Selection.Count To 1 Step -1
Set objMessage = Application.ActiveExplorer.Selection.Item(intX)
objMessage.Move objInbox
Next

Set objMessage = Nothing
Set objInbox = Nothing
Set objNS = Nothing

EH:
If Err.Number <> 0 Then
Stop
End If
End Sub

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS
2007
& WSS 3.0 Application Development)
Collaborative Innovations
-> Try Picture Attachments Wizard For Microsoft Outlook <-
Web: http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault


Amir Atary said:
Hello to all :)

I need help regarding writing a macro.

I would the follow senario to happen: when highlighting an email under
inbox i want to move it to inbox folder under personal folder (pst).

Any help will be appriciated.

Thank you very much :)
Amir
 

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