Results 1 to 15 of 15
  1. #1
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automating Contacts Exports (OL2000)

    Hi there,

    As a backup measure I routinely export my contacts folder with its subfolders to a PST file. I then close Outlook (so it lets go of the newborn PST), encrypt the PST and e-mail it to an account I keep for storage purposes.

    However, I find this procedure kind of awkward to the extent that I tend to delay it as much as possible. So I tought about using VBA to automate the relevant part within Outlook.

    I've had experiences with VBA in Access and Excel, but don't know where to start in Outlook. For instance, I don't know what to call the "ThisOutlookSession" thing hanging from "Project 1" in the VB Editor. Does anyone have a hint?

    Thank you in advance
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Automating Contacts Exports (OL2000)

    > I don't know what to call the "ThisOutlookSession" thing hanging from "Project 1" in the VB Editor. Does anyone have a hint?

    I'm not sure what that is called either, other than ThisOutlookSession. Is it important? If you plan to automate Outlook (so that you can close it and continue executing code), it probably is easier to store your code externally, whether in a VB form, a VBScript file, or another VBA host.

    Some potentially useful objects and methods:

    <code>dim appOutlook as Outlook.Application
    dim ns as Outlook.NameSpace
    'get/create application -- snag code from elsewhere
    'create ref to namespace
    set ns = appOutlook.GetNamespace("MAPI")
    'create new pst for "export"
    dim strName as string, strPath as string
    strname = "backups_contacts-" & format(Date,"yyyymmdd")
    strpath = "c:" & replace(strname,"_","") & ".pst"
    ns.AddStoreEx strpath,olStoreUnicode
    'why doesn't that method return a reference to the folder? beats me...
    'choose source and destination (new PST) folders
    dim fldSource as outlook.mapifolder, fldDest as outlook.mapifolder
    set fldsource = ns.pickfolder
    set flddest = ns.pickfolder
    'copy source folder; might need to iterate over subfolders
    fldsource.copyto(flddest)
    'close/disconnect new PST (rename from generic "Personal Folders" now that we know fldDest)
    flddest.name = strname
    ns.removestore(strname)
    'exit Outlook
    ns.logoff
    appOutlook.Quit
    set flddest = nothing
    set fldsource = nothing
    set ns = nothing
    set appOutlook = nothing
    'now do file system stuff with strPath</code>

  3. #3
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    Hello Jefferson,
    <hr>I'm not sure what that is called either, other than ThisOutlookSession. Is it important?<hr>
    Not really so. I was trying to mean I didn't know whether that was the right place to place the VBA script on. On one hand, it seems important because it has a name. On the other hand, there's only ONE such thing. That confused me.
    <hr>If you plan to automate Outlook (so that you can close it and continue executing code), it probably is easier to store your code externally, whether in a VB form, a VBScript file, or another VBA host.<hr>
    I understand what you say, but I don't have the VB standalone product at home. I might try learning how to code the script at work, but that will take some spare time put to good use. As for VBScript, I don't know how to use it either. Does it require any programming package?

    Regarding the code itself, I'll need some time to understand it and if possible ellaborate on it a little. I'll get back to you when I have some news.

    Thank you for your time!
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Automating Contacts Exports (OL2000)

    VBScript is similar to VBA, but with just enough differences to give you a headache. You might consider using Excel as your host. Just create a new module in a workbook, add a reference to the Microsoft Office Outlook object library (Tools>References in the VB Editor), and automate Outlook from there.

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Automating Contacts Exports (OL2000)

    A couple of things that may help explain stuff further.

    You have probably figured out that Outlook doesn't have a macro recorder. The Outlook Object model is very far from fully exposed the way Word, Access, PowerPoint and Excel are - partly because Outlook is a mix of a MAPI mail engine and a PIM, and very probably because Microsoft is trying to limit the use of Outlook as a spam engine. For example, the file export capabilities you find in the Outlook menu are not exposed, presumably because someone could write a virus to steal contacts email lists too easily. However there are other things that are not exposed in the Object model which I can't fathom as being a target of potential viruses, such as the detail of user Views, so who knows why MS is limiting exposure of some sections the Object Model.

    The 'ThisOutlookSession' module is a kind of Class Module, primarily geared to providing a location for hooks into Outlook Events. ThisOutlookSession can also hold non-event code, or you can create a separate Module for other code just as you would in any other Office program.

    For a couple of examples of code that sucks Contact information out into another format, see Jefferson's and Rory's posts using ADO in <!post=this VBA thread,510884>this VBA thread<!/post>, or to get ALL the Contact Properties, you could try my <!post=post in Excel,511008>post in Excel<!/post> which is WAY slower than the ADO methods. If you use a VBA technique to directly access Contact Properties, install ClickYes.

    HTH.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    Good. Your explanation will help me work things out. I'll keep you posted.
    Thanks!
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  7. #7
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    Hello John,

    Thanks for your input too. I couldn't get hands to this today, but hopefully I'll get started this weekend.
    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  8. #8
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    Hello Jefferson and John,

    It's been a while since I last posted. Well here's what I tried:

    1) I first tried using Excel and Word as hosts for the VBA code. I could advance very little. I was aware that Outlook's object model was somewhat different, as John states above. In fact I got to know Outlook Redemption before my first post. But I had the hope a simple export wouldn't require me sitting for so long. I don't have the time to deal with this "cleanly", so instead
    2) I wrote a little AutoIt script that, although not so politically correct, does the work. I can post the script if you will, but I don't think it will be of much use because it's based on Send() and Sleep() functions, the former being reliant on the Outlook version and language. So instead of dealing with objects it just automates human keystrokes. The procedure is automated to the extent of closing Outlook via Alt+F4. What's left for me is to check that no instance of Outlook.exe is still running in the background, zip the resulting PST file and finally email it to one of my hosting accounts.

    I appreciate all your time and dedication. I'm sure I'll have another go at this some time in the future, but I don't have the time right now.

    Thank you!
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Automating Contacts Exports (OL2000)

    I wouldn't describe Send() or the VBA method SendKeys as politically incorrect. Just not reliable enough to distribute to others as a general purpose solution due to potentially strange timing issues and environmental differences.

  10. #10
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    I agree.

    BTW, when I first picked this up I tried placing VBA code in the ThisOutlookSession module. I believe this is what caused Outlook to prompt me to enable/disable macros each time I click on the SpamBayes (a third-party antispam plugin) "Delete as Spam" toolbar button (see attached). I removed the code in the module but I still get prompted.

    Has something similar ever happened to you? Is there something I can do to stop Outlook from prompting me?

    Thanks

    Edited to include attachment
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Automating Contacts Exports (OL2000)

    If SpamBayes is not "signed" in a manner that bypasses security, then you should receive a request for permission. Did it behave differently before? Perhaps the checkbox to trust add-ins got unchecked (or maybe I am thinking of Word...).

  12. #12
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Automating Contacts Exports (OL2000)

    Or perhaps you changed Macro Security from Low to Medium?
    -John ... I float in liquid gardens
    UTC -7ąDS

  13. #13
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    Hi Jeff,

    Yes, SpamBayes used to behave OK before I placed the code in the module. I clicked on the toolbar button and nothing happened, except that the message was processed and then sent to the SPAM folder. No prompts.
    I cannot find the checkbox you mention. Where is it supposed to be? I'm using OL 2000.
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  14. #14
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    Not intentionally. However, I cannot find that dialog box / tab either. There's a Security tab in Tools | Options, but nothing like what you mention in there...
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  15. #15
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating Contacts Exports (OL2000)

    Found it - Bingo.

    As I mentioned I didn't change it manually, so altering the ThisOutlookSession module must have set the security to Medium.

    Thanks again Jeff and John for your help!
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •