Link to home
Start Free TrialLog in
Avatar of Geo123
Geo123

asked on

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
Avatar of Geo123
Geo123

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of stefri
stefri
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Geo123

ASKER

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
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
Avatar of Geo123

ASKER

ok Stefri that appears to be running...how do I loop through all emails in in box????
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
Avatar of Geo123

ASKER

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
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
Avatar of Geo123

ASKER

ok stefri.... will test that. it was outwith scope of my question so will add some points
Avatar of Geo123

ASKER

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
Avatar of Geo123

ASKER

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
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
Avatar of Geo123

ASKER

> 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
Avatar of Geo123

ASKER

> 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
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!!!
Avatar of Geo123

ASKER

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
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
Avatar of Geo123

ASKER

If the user doesnt insatl Redemption...they can still get Sender email?
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
Avatar of Geo123

ASKER

ok will try this.... running on Outlook 2000
cheers

George