[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Outlook VBA or Access to look through all messages in folder

Posted on 2004-11-12
21
Medium Priority
?
1,402 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Geo123
  • 12
  • 8
20 Comments
 
LVL 3

Author Comment

by:Geo123
ID: 12568295
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
 
LVL 13

Accepted Solution

by:
stefri earned 2000 total points
ID: 12578197
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
 
LVL 3

Author Comment

by:Geo123
ID: 12582781
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:stefri
ID: 12586478
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
 
LVL 3

Author Comment

by:Geo123
ID: 12657008
ok Stefri that appears to be running...how do I loop through all emails in in box????
0
 
LVL 13

Expert Comment

by:stefri
ID: 12660012
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
 
LVL 3

Author Comment

by:Geo123
ID: 12663743
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
 
LVL 13

Expert Comment

by:stefri
ID: 12669136
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
 
LVL 3

Author Comment

by:Geo123
ID: 12673539
ok stefri.... will test that. it was outwith scope of my question so will add some points
0
 
LVL 3

Author Comment

by:Geo123
ID: 12695037
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
 
LVL 3

Author Comment

by:Geo123
ID: 12695269
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
 
LVL 13

Expert Comment

by:stefri
ID: 12699170
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
 
LVL 3

Author Comment

by:Geo123
ID: 12705500
> 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
 
LVL 3

Author Comment

by:Geo123
ID: 12705536
> 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
 
LVL 13

Expert Comment

by:stefri
ID: 12709635
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
 
LVL 3

Author Comment

by:Geo123
ID: 12738241
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
 
LVL 13

Expert Comment

by:stefri
ID: 12749205
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
 
LVL 3

Author Comment

by:Geo123
ID: 12754781
If the user doesnt insatl Redemption...they can still get Sender email?
0
 
LVL 13

Expert Comment

by:stefri
ID: 12757249
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
 
LVL 3

Author Comment

by:Geo123
ID: 12883222
ok will try this.... running on Outlook 2000
cheers

George
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question