Outlook VBA or Access to look through all messages in folder

HI all

Have been tasked with fixing an overflowing inbox in outlook. Need routine to debug print all Folders/ mailboxes. Just out put names

Then next part is routine to access 1 of boxes above and go through all email items....... in Inbox

Look at email address or for word Account in Subject or body........

That should be enough for now

Am going to do link to access data to match Email or account no

cheers

George
LVL 3
Geo123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geo123Author Commented:
ok after some messing about  I have found I have my email box and another attached to my account. Under additional Mailboxes in Outlook.

If I use myNameSpace.CurrentUser.Name I get my mailbox, using MAPI at GetNamespace.

So how do I change to Mailbox - Online ??????

cheers

George
0
stefriCommented:
To access other mailbox Inbox

Function getStore(shdMbx)
Dim entryID As String
Dim storeID As String
Dim myFolders As Object
Dim myFolder As Object
Set myFolders = objNS.folders

For Each myFolder In myFolders
 

If myFolder Is Nothing Then
    MsgBox "Cannot get first Folder object"
    set myFolders = nothing
    Exit Function
End If
If shdMbx = myFolder.Name Then
    Dim i As Integer
    For i = 1 To myFolder.folders.Count
        If myFolder.folders(i).Name = "Inbox" Then
            entryID = myFolder.folders(i).entryID
            storeID = myFolder.folders(i).storeID
            Exit For
        End If
    Next

   
   Set getStore = objNS.GetFolderFromID(entryID, storeID)
   Set myFolders = nothing
   Exit Function
End If
Next
 
End Function

Private Sub Application_Startup()
  Dim myshared As Object
  Set objNS = Application.GetNamespace("MAPI")
  Set myshared = getStore("Mailbox - Online")

End Sub
stefri
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geo123Author Commented:
HI stefri....  I put that code in and got runtime error 424, object required

For this line   Set myFolders = objNS.Folders

I notice there is no dim' ing of objNS... is this the namespace???

cheers

George
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

stefriCommented:
Sorry, you are right
Dim objNS as Outlook.Namespace (global scope)
It is part of a code I modified apparently a little to fast

Stefri
0
Geo123Author Commented:
ok Stefri that appears to be running...how do I loop through all emails in in box????
0
stefriCommented:
myshared  is the Inbox of the sharedmailbox you want to monitor
dim itm as variant
for each itm in myShared.Items
     ' dowhatever you want with itm which represents a mail, a meeting request, a task assignment...etc.
next

Stefri
0
Geo123Author Commented:
cool Stefri.... thats working as I loop through mailbox I get the mail items.

I would like to move each email as the routine processes them....how do I do this???

cheers

George
0
stefriCommented:
Moves an Outlook item to a new folder.

expression.Move(DestFldr)

expression   Required. An expression that returns one of the objects in the Applies To list.

DestFldr   Required. An expression that returns a MAPIFolder object. The destination folder.
In your case:

for each itm in myShared.Items
    itm.move DestFldr
next
In VBA, check View/Object Viewer where you get inline help

Stefri
0
Geo123Author Commented:
ok stefri.... will test that. it was outwith scope of my question so will add some points
0
Geo123Author Commented:
ok Stefri this is doing me heed in....... am creating a reply to email I process...... what property do i get email address from ??

Have done this before using myItem.ReplyRecipients.Item(1).Address....its not playing now..... am in Outlook 2000

cheers

George
0
Geo123Author Commented:
Stefri...further woes..... it appears in outlook if email I get in has J Smith [some@email.co.uk] then SenderName gives just J Smith.....how do I get to email??
I prepare reply (myitem.reply). If its just George@aol.com then thats fine

also when I goto move email that been dealt with to folder processed  myItem.Move "Processed", it cant find it...... think its looking in my mailbox folders and not attached Mailbox- Online

Then when I sent the email it sends from my email box with mt sender name on it and puts it in Sent Items, not the online Sent Items.

What u reckon???

cheers Geo
0
stefriCommented:
If you reply a mail, by default it will use the reply addres which is in the mail: so no need to specify one
SenderName is the visible part of email address, you cant use this property
If you need the email address itself, you will need extra soft (redemption.dll) to avoid security warning
if you want to move to a folder not in your default profile but from the sahred mailbox, you have to use the Folders propertiy of myshared (which is Inbox folder)
if you want to get the parent of this inbox
myshared.Parent
subfoders at same level as this inbox
myshared.Parent.folders
sub folders of this inbox
myshared.Folders
Check Folders property in VBA help

>>>>>Then when I sent the email it sends from my email box with mt sender name on it and puts it in Sent Items, not the online Sent Items.
It is the standard behaviour

stefri
0
Geo123Author Commented:
> If you reply a mail, by default it will use the reply addres which is in the mail: so no need to specify one
         how?

>If you need the email address itself, you will need extra soft (redemption.dll) to avoid security warning

if you want to move to a folder not in your default profile but from the sahred mailbox, you have to use the Folders propertiy of myshared (which is Inbox folder)
if you want to get the parent of this inbox
myshared.Parent
subfoders at same level as this inbox
myshared.Parent.folders
sub folders of this inbox
myshared.Folders
Check Folders property in VBA help

>>>>>Then when I sent the email it sends from my email box with mt sender name on it and puts it in Sent Items, not the online Sent Items.
It is the standard behaviour
0
Geo123Author Commented:
> If you reply a mail, by default it will use the reply addres which is in the mail: so no need to specify one
         how?

>If you need the email address itself, you will need extra soft (redemption.dll) to avoid security warning
       I have no idea how to do this

if you want to move to a folder not in your default profile but from the sahred mailbox, you have to use the Folders propertiy of myshared (which is Inbox folder)
if you want to get the parent of this inbox
myshared.Parent
subfoders at same level as this inbox
myshared.Parent.folders
sub folders of this inbox
myshared.Folders
Check Folders property in VBA help

         ok will try this

>>>>>Then when I sent the email it sends from my email box with mt sender name on it and puts it in Sent Items, not the online Sent Items.
It is the standard behaviour
......ok

I am not very good at Outlook coding...not done much of it........ deffo need to have email as I use it to look up customer in database and amend there record with the email. I will up points to 500 if u solve these issues for me.......... how can u resisit 500 Stefri!!!!

Need it to finish of piece of work.... becoming urgent

cheers

George
0
stefriCommented:
Let' say you are foreach'ing itm in the myShared.Items
To reply: itm.Reply or itm.ReplyAll should be preadressed to the sender
Redemption is avalaible at http://www.dimastr.com/redemption/, it bypasses MS security if you use what they call a safeitem
Install it.
then

dim SafeItem, oItem  

dim itm as variant
for each itm in myShared.Items
     set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
     set oItem = itm.ReplyAll
     SafeItem.Item = oItem 'set Item property  
     SafeItem.Send
     set SafeItem = Nothing
next

How do you look up your customer? Which info is used? Email Address, Name
If Email Address from a received mail:

dim senderAddress as string
dim SafeItem, oItem  
dim PrSenderEmail as Long
PrSenderEmail = &H0C1F001E
dim itm as variant
for each itm in myShared.Items
     set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
     set oItem = itm
     SafeItem.Item = oItem 'set Item property  
     senderAddress = SafeItem.Fields(PrSenderEmail)
     set SafeItem = Nothing
next
Should do the trick
Stefri
PS: I am not related to dimastr but it is a wonderful tool which is free on top of that!!!
0
Geo123Author Commented:
Stefri.... mind I have Nal'ed PCs  (Or rather my users do) if this redemption needs installed it may pose a problem!!!!

Ow god do I have to buy it...groan...red tape!!!!

Will try it but nal and buying part will stuff me i think
0
stefriCommented:
deplying Redemtion shold be done with a Netlogon, I think
If you do not want to install, you users will have to click yes when the security popup is displayed
you do not need to buy: it is a real freeware, you only pay if yo need he dll in a software to be sold.
stefri
0
Geo123Author Commented:
If the user doesnt insatl Redemption...they can still get Sender email?
0
stefriCommented:
Tricky to get
Sub testSend()
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
 
  On Error Resume Next
  If myOlSel.Count > 0 Then
    Dim oRep As Outlook.MailItem
    Set oRep = myOlSel.Item(1).Reply
    Dim recip As Outlook.Recipient
   
    For Each recip In oRep.Recipients ' GENERATES A SECURITY WARNING avoided with redemption and code as provided in previous post
        MsgBox "To: " & recip.Address
    Next
        Set recip = Nothing
   oRep.Close False
   Set oRep = Nothing
  End If
  Set myOlExp = Nothing
Set myOlSel = Nothing
End Sub

stefri
PS: tested on OL2002
0
Geo123Author Commented:
ok will try this.... running on Outlook 2000
cheers

George
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.