Outlook VB WTF



  • [code]
    Set myNameSpace=objOL.GetNameSpace("MAPI")
    myNameSpace.logon "", "", True, True
    Set Inbox = objOL.GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders)
    Set myFolder = inBox.Folders(16) ' Go down X folders 15
    Set myfolder2 = myfolder.Folders(9) ' Now, in that folder, go down X more 9
    Set myfolder3 = myfolder2.Folders(12) ' Now from THAT folder, go down X!
    'Set myfolder4 = myfolder3.Folders(4) Folder structure changed, this is no longer needed.
    Set collMail = myfolder3.items ' Show me what's in there (I was a latch key kid, forgive me)
    [/code]

    What is it? It's a script written to monitor the count of error emails inside of a public folder. It breaks all the time, because administration is always adding folders inbetween myfolder and myfolder4, making the script search through an entirely different folder. I can't find another way in VBS to grab it. So my other alternatives are:

    Perl:
    One line achieves all the above -       $imap->select($myPublicFolder) or die "Something bad happened: $@";

    Or Vb.Net with MSXML2:
          oXMLHttp.open("SEARCH", sUrl, False, "username", "password")
    Which is sort of a hack, since it's using OWA to grab the info and is a lot slower then the Perl method.

    Messed up eh?



  • So can't you iterate through the folders by name? I assume they are just adding other unrelated folders, not changing the name of the folders you care about.

    Either:

    Set myFolder = inBox.Folders("Sales")

    if that syntax is supported, or if its not:

    For i = 1 to inbox.folders.count
    if inbox.folders(i).name = "Sales" then
    set myfolder = inbox.folders(i).name
    exit for
    end if
    next

    Something like that?



  • That's the thing - for all the user groups I posted this on, all the Google searches performed, and that seems to be the only way to do it via VBS.
    I'm not positive, but I don't think I can retrieve names of the folders beyond the default public folder. I'll have to re-research it, since this is over a year old, to be sure though.

    I just thought it was funny that it was so easy to query with one line of Perl, and have it always work, versus multiple lines of VBS or a semi-hack of VB.Net.

    Then again I'm not a programmer, whatever the people in my department may think - I write scripts, sure, the occasional VB this or Perl that, but nothing huge. Hell, I still have a helluva time understanding hashes and mapping keys and such.

    @BradC said:

    So can't you iterate through the folders by name? I assume they are just adding other unrelated folders, not changing the name of the folders you care about.

    Either:

    Set myFolder = inBox.Folders("Sales")

    if that syntax is supported, or if its not:

    For i = 1 to inbox.folders.count
    if inbox.folders(i).name = "Sales" then
    set myfolder = inbox.folders(i).name
    exit for
    end if
    next

    Something like that?



  • You should be able to replace those indexes with the string names:

    @MSDN said:

    Using the MAPIFolder Object

    Use Folders(index), where index is the name or index number, to return a single MAPIFolder object from a NameSpace object or another MAPIFolder object.

    the relevant page



  • Outlook + VB = WTF

    I tried making my own customized spam filter. Outlook would trigger my code when a new email was received, and I'd examine the body of the message to look for specific patterns. None of this was resource-intensive, but for some reason at totally random times, the code would bomb without any descriptive error message, and my Outlook rule would be disabled. I'd re-enable it, and try to track down the error by running the rule on my entire Inbox...and then it would work perfectly.

    It would be fine for the next two days, catching spam and filing it in the proper folder, and then BAM broken again.

    Don't try to automate anything in Outlook, it's a pain in the ass.

    In other news, I try not to create unnecessary objects, so you can do this:

    <FONT face="Lucida Console" size=2>Set myNameSpace=objOL.GetNameSpace("MAPI")
    myNameSpace.logon "", "", True, True
    Set Inbox = objOL.GetNamespace("MAPI").GetDefaultFolder(olPublicFoldersAllPublicFolders)
    Set myFolder = inBox.Folders(16).Folders(9).Folders(12).Folders(4)</FONT>

    Or at least that's the theory, it's untested but I'm 99% sure it's OK.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.