I am writing code to redirect mails from perticular EmailAddress.
For that i am giving user a form in which all the folders in outlook will be listed.
I am not getting the code to do this.
I can do this if i want to list folders from perticular folder like inbox by this :
Code:
Set myOlApp = CreateObject("Outlook.Application")
Set name = myOlApp.GetNamespace("MAPI")
Set fldFolder = name.Folders("olinbox")
'For Each prfolder In fldFolder
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Call GetFolderInfo(fldFolder)
GetFolderInfo is listing folders in fldfolder.
But i want to check for all folders in outlook.(like folders in outbox, inbox....)
Hi v_gyku,
It is me again So check out the attached code. It's a very usefull application and all my coleagues thanked me three times for creating this It is saving all attachments from all e-mails in selected directory. It creates a directory structure on the disk exactly like the one in your e-mail account. Also check out the filters
Tell me you opinion about it
You liked it? Please show your gratitude and rate it!
Private Sub CommandButton1_Click()
Dim NS As NameSpace
Set NS = Application.GetNamespace("MAPI")
listSubFolders NS.Folders(1)
End Sub
Private Sub listSubFolders(f As MAPIFolder, Optional i As Integer)
Dim x As MAPIFolder
For Each x In f.Folders
' Optional test for email type folders only
' If x.DefaultItemType = olMailItem Then
listFolders.AddItem x.EntryID
listFolders.Column(1, listFolders.ListCount - 1) = String(i, "-") & x.Name
If x.Folders.count > 0 Then listSubFolders x, i + 1
' End If
Next
End Sub
I have this code , but its giving me error on this lin :
Hi v_gyku,
It is me again So check out the attached code. It's a very usefull application and all my coleagues thanked me three times for creating this It is saving all attachments from all e-mails in selected directory. It creates a directory structure on the disk exactly like the one in your e-mail account. Also check out the filters
Tell me you opinion about it
If i select a folder which is not user cretaed then my code works fine.
But if try to route a message to a user created folder then it fails.
gives error: The operation failed. Object could not be found.
Code:
final1 = txtBrowse1.Text
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myOlApp = CreateObject("Outlook.Application")
Set fldFolder1 = myNameSpace.Folders(1)
Set myInbox = myNameSpace.Folders(1)
If final1 = "" Then
txtBrowse1.SetFocus
Else
Dim eidctr, post As Integer
eidctr = eid1.Count
post = 1
While eidctr > 0
MsgBox (fldFolder1.Folders.Item(eid1.Item(post)))
Set myDestFolder = fldFolder1.Folders.Item(eid1.Item(post))
eidctr = eidctr - 1
post = post + 1
Wend
End If
I am taking entry id of each folder in eid. iTs a collection.
I am listing all folders in outlook.
User will select any folder from a listbox.
User will select an email id from another listbox.
When he clicks on command button all the messages from selected email id will be shifted to selected folder.
If i am selecting a folder like inbox, outbox,drafts, junk email....(which r not user cretaed.) then my code is working fine.
But if i select user selected folder it gives me error: The operation failed. Object could not be found.
I Know all of these stuff.but not in VB in VC++ i can do.So if you wann idea how to do.i can tell .How to implement it's upto you.So exactly what the question and what is the issue here Please let me know.
CComQIPtr<MAPIFolder> pFolderAcct1;
CComQIPtr<Outlook::_MailItem > pMailItem(pDisp);
CComPtr<IDispatch > pDispatch;
if(pMailItem)
{
hr = pMailItem->Move(pFolderAcct1,&pDispatch);
//pFolderAcct1 Where you want to move your E_Mail
if(FAILED(hr))
return hr;
}
This way uou can Move Your data From One Folder to Another.
But Still One Confusion is there For Me .What yopur require Ment and What u want
.if you wann you also can Check In MSDN for Application Object and you will find all the nMethod related with OUtlook or you can check ms09out.tlf File For looking various interfaces Provided by Outlook.
if Still you have Problem Explain your Question Once Agin .that What's your requirement and What you want.
Its not working if folder is ceated inside anyother folder.So, its not an issue with user created folder.
If i create a folder in personal folder itself then its ok. But if i create folder inside a inbox or outbox or.... then problem.
What i have to do to access these folders also.
I dont want to give names of the folders explicitely.
Suppose i have selected 2 folders from listbox mesage should be moved to these two folders.
Code:
Dim outarray() As Variant
Dim outarrayfolder() As Variant
Dim arrsizefolder As Integer
Dim tempfolder As String
Dim destfld As String
Dim arrsize As Integer
Dim abcde As String
Dim final1 As String
Dim fldFolder1 As MAPIFolder
Dim myDestFolder As MAPIFolder
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem 'Object
final1 = txtBrowse1.Text ' this is folder selected
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myOlApp = CreateObject("Outlook.Application")
Set fldFolder1 = myNameSpace.Folders(1) 'Personal folders
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) 'myNameSpace.Folders(1) 'inbox
Dim objfolder As Outlook.MAPIFolder
If final1 = "" Then
txtBrowse1.SetFocus
Else
Dim eidctr, post As Integer
eidctr = eid1.Count
post = 1
While eidctr > 0
MsgBox (fldFolder1.Folders.Item(eid1.Item(post))) 'It should display name of folder selected.
Set myDestFolder = fldFolder1.Folders.Item(eid1.Item(post)) 'sets the destination folder
eidctr = eidctr - 1
post = post + 1
Wend
End If
Set myItems = myInbox.Items
Dim folder As MAPIFolder
j = myInbox.Items.Count
For Each myItem In myInbox.Items
If myItem.Class = olMail Then
If myItem.SenderEmailAddress = final Then 'final contains emailaddress
myItem.Move myDestFolder
End If
End If
Next
inp = Mid(inp, InStr(inp, delim) + 1)
arrsize = arrsize + 1
Wend
My main problem is how will i set destination folder as folder inside inbox or outbox or...........,at the same time it can be inbox outbox.......
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.