?
Solved

Refering to Inbox subfolders in VB

Posted on 2003-03-05
9
Medium Priority
?
442 Views
Last Modified: 2010-04-07
I currently have a program that checks Outlook 2000 every 60 seconds for new emails that have Attachments with a specific naming convention, when found the Attachment is copied to an external directory for pickup by a Mainframe program. The actioned email is then moved to a subfolder of Inbox, in Outlook 2000. Currently there is only 1 subfolder so I can get away with refering to this subfolder as follows:

Set oSubFolder = oFolder.Folders.Item(1)

Thus using oSubFolder whenever I mean the subfolder.

My challenge: they want to add ~50 new subfolders now and some more later.

My Question: Is there a way to refer to a subfolder by name rather than by item number, as the relative position of subfolders is probably going to change with each set of additions and probably deletions.

Thanks,
vbmds
0
Comment
Question by:vbmds
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 16

Accepted Solution

by:
Neo_mvps earned 600 total points
ID: 8077555
Yes, the item method accepts a number or name of folder as an arguement.  The only thing they/you have to keep in mind is that each folder name under Inbox is unique.
0
 

Author Comment

by:vbmds
ID: 8078004
Thanks Neo_mvps, this confirms what my books and online documentation hint at. Unfortunately thats all they do, and thus do not give any sort of example to play around with.

Anyway this gives me a starting point,

Thanks,
vbmds
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 8094543
Just wondering about the need for polling each minute. You can subscribe to an event when the mail arrives, so wouldn't this be better

Private WithEvents gFolInboxItems As Outlook.Items

Private Sub Application_Startup()
    Set gFolInboxItems = Application.GetNamespace( _
                                "MAPI").GetDefaultFolder(olFolderInbox).Items
   
End Sub

Private Sub gFolInboxItems_ItemAdd(ByVal Item As Object)

    Dim lMailItem As Outlook.MailItem
    If Item.Class = olMail Then
        Set lMailItem = Item
    Else
        ' We're only interested in Mails
        Exit Sub
    End If

    Dim theAttachment As Attachment
    For Each theAttachment In lMailItem.Attachments
        If MatchesNamingConvention(theAttachment.FileName) Then
            ' Do your stuff
        End If
    Next

End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vbmds
ID: 8099242
DominicCronin,

Thanks. That is a little more straightforward than what I've done. However, this has been my first time programming to Outlook, and given the fact that the project was a emergency short term stop gap measure I didn't have much time to learn about Outlook, about 12 months ago.  If I get to rewrite the program I will certainly look to make use of your suggestion.

So, thanks again for your input.

vbmds
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 8105116
I know what you mean - Outlook is very poorly documented. I don't do much Office programming, but I have to say that it's harder than it should be. For example, the VBA help that ships with Office XP (which is what I'm using) seems to refer to Office 2002, and the examples don't seem to work with the Object model I can see!!!

Anyway - what the heck is an Explorer, or an Inspector, or whatever? How do these things map to the stuff you see in the user interface. Rant, rave, spit, scream, stamp etc.
0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 8105280
Explorer = Main Outlook window that shows a folder

Inspector = Window that is displaying an item. (Note: Inspector can behave oddly when Word is enabled as your editor.)

FWIW, Look for a book by Sue Mosher (owner/operator of http://www.slipstick.com).  She is probably one of the best writers that I have seen for beginning to intermediate users that want to work with the Outlook Object Model.
0
 

Author Comment

by:vbmds
ID: 8107491
I have to say that much of the code source I use for my Office work starts life as code snipits by Sue Mosher and other contributors to Slipstick.com. Other than this site, Slapstick.com is the most valuable resource.

DominicCronin, luckily for me I only have to work with Office97 and Office2000. I really dislike VBA for Office work, its like coding HTML in notepad, you don't get any real-time feedback and when you have 10K lines of the stuff its a nightmare!

While I have both your attention a small question: the outlook program is up and running but I have found that a For Each Next statement that is supposed to process each email in the Inbox dumps out after about 50% done and appears to have lost/forgot what collection it is supposed to be processing the items from. It does not make too much impact as the program picks up where it left off next iteration, it just a bit puzzeling.
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 8113583
Thanks for the hints from both of you. I'll definitely have a look at slipstick.

Meanwhile, vbmds, can you post a code snippet illustrating your problem? Are you working in Vb or VBA? If the former, then I guess you could try to set the debugger up to break on all errors to see if there's any more info to be had. (I don't know if that's possible in VBA)
0
 

Author Comment

by:vbmds
ID: 8115050
I'm using VB. There does not appear to be any errors, it just forgets what its doing. I probably should kick off another question with some points.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

765 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