Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Star Lounger
    Join Date
    May 2003
    Location
    Whitmore Lake, MI , USA
    Posts
    84
    Thanks
    13
    Thanked 0 Times in 0 Posts

    writing Outlook macros (Win XP home)

    I use Outlook 2003 at home and on my work PC. I use my PDA as my dayplanner, using Franklin Covey's PlanPlus for Outlook. My employer has recently declared that we can not hotsync our PDA's at work for fear of violating patient confidentiality (I work in a VA hospital). I would like to create a macro that will copy my Franklin Covey Plan Plus, Contacts, and Calendar folders to pst files that I could WinZip and then e-mail to myself at home. Then I'll import them to Outlook and home and hotsync so all my appointmetns and such are consistent.

    Can anyone recommend a good book or resource site that can teach me how to write one, since Outlook doesn't allow one to record macros? Any push in the right direction will be deeply appreciated!

    Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: writing Outlook macros (Win XP home)

    You'll find a starting point with some useful links in Writing VBA code for Microsoft Outlook.

    Warning: the object model for Outlook is limited and not very intuitive.

  3. #3
    Star Lounger
    Join Date
    May 2003
    Location
    Whitmore Lake, MI , USA
    Posts
    84
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Re: writing Outlook macros (Win XP home)

    I'll check it out. I used to do BASIC back in primitive times (i.e. the early/mid 1980's). Can an old dog pick up these tricks with any relative ease?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: writing Outlook macros (Win XP home)

    Why not? I'd study examples to see how various tasks are handled in Outlook VBA. You'll find lots of examples on the site I referred to, and also here on Woody's Lounge.

  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: writing Outlook macros (Win XP home)

    Hans has beaten me to it, but the website he refers to, Sue Mosher's http://www.outlookcode.com, is also helpful in addition to her book Microsoft Outlook Programming. Search the site for similar posts (the search box on the upper right is very small - you don't need to register to use it.) As Hans states, the Outlook VBA model is very strange and piecemeal, and has a number of security annoyances, because (i) Outlook was built in two general parts - a MAPI service, and a PIM, and (ii) MS doesn't want Outlook used as a spam engine.

    We here at Woody's Lounge in the Outlook Forum will also be happy to help you. My initial thought is that the macro will need to create a new PST information store (an information store is usually a PST, an Exchange Server Mailbox, or a Public Folder store) and then copy the folders you need to that store. Then you will have to completely close Outlook (since it doesn't release information store files even when they are closed) and run the rest of your process manually or via VB Script (or WinZip script if there is such a thing - I don't use it). An information store is a folder in Outlook VBA - the root folder of each store - see the attachment to <post#=701,815>post 701,815</post#>. A new store is created using .AddStore (not that simple - must also first create the NameSpace object, and specify the path and name for the new storage file).

    Good luck, post back if you have questions or need help.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    Star Lounger
    Join Date
    May 2003
    Location
    Whitmore Lake, MI , USA
    Posts
    84
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Re: writing Outlook macros (Win XP home)

    Thanks. I went to her site and may have found a script that writes the pst file. I just need to learn to tweak it to write all 3 or make a version for each file. But, I want to learn the language a bit so I know what I'm doing (yes, a dangerous concept...).

    Thanks for all the quick input. It is appreciated!

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

    Re: writing Outlook macros (Win XP home)

    You may be able to copy the three folders you need to transfer into a single new PST - that should simplify parts of the process and code.
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    Star Lounger
    Join Date
    May 2003
    Location
    Whitmore Lake, MI , USA
    Posts
    84
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Re: writing Outlook macros (Win XP home)

    Well, I went to that site and found the following macro script there called copypst2pst. Ms. Mosher said it should serve my needs:

    Sub PDA()
    Dim olAPP, olNameSpace, olFolder
    Dim newStore, newContacts, NewContactItems
    Dim colItems, myItem
    Dim myStore, myContacts
    Dim copyItems, moveItems
    Dim intCount

    On Error Resume Next

    'Open and Set outlook
    Set olAPP = CreateObject("Outlook.Application")
    Set olNameSpace = olAPP.GetNamespace("MAPI")

    'Open and set new PST
    olNameSpace.AddStore "M:F Coveycontacts.pst"
    Set olFolder = olNameSpace.Folders.GetLast
    Set olFolder.Name = "Contact List"
    Set newStore = olNameSpace.Folders("Contact List")
    Set newContacts = newStore.Folders("Contacts")
    Set NewContactItems = newContacts.Items

    'Set new PST and delete old contacts
    Set myStore = olNameSpace.Folders("Personal Folders")
    Set myContacts = myStore.Folders("Contacts")
    Do Until intCount = 100
    Set colItems = myContacts.Items
    Set myItem = colItems.GetNext
    For Each myItem In colItems
    myItem.Delete
    Next
    intCount = intCount + 1
    Loop

    'Copy new contacts
    Set copyItems = NewContactItems.GetNext
    While TypeName(copyItems) <> "Nothing"
    Set moveItems = copyItems.Copy
    moveItems.Move myContacts
    Set copyItems = NewContactItems.GetNext
    Wend

    'Close new PST
    olNameSpace.RemoveStore newStore

    'Clean up
    Set olAPP = Nothing
    Set olNameSpace = Nothing
    Set olFolder = Nothing
    Set newStore = Nothing
    Set newContacts = Nothing
    Set NewContactItems = Nothing
    Set colItems = Nothing
    Set myItem = Nothing
    Set myStore = Nothing
    Set myContacts = Nothing
    Set copyItems = Nothing
    Set moveItems = Nothing
    Set intCount = Nothing

    End Sub

    YABUT! When I ran it. my entire PC bogged down. When I stopped and restarted Outlook and ran the macro via the Step Into function, it seemed to bog down at this point:

    'Copy new contacts
    Set copyItems = NewContactItems.GetNext
    While TypeName(copyItems) <> "Nothing"
    Set moveItems = copyItems.Copy
    moveItems.Move myContacts
    Set copyItems = NewContactItems.GetNext
    Wend

    I held down the F8 key for at least 5-10 minutes with it stuck in the loop and I have no way near that many contacts in Outlook...lol

    Any guesses, clues, or wild ideas?

    Thanks!

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: writing Outlook macros (Win XP home)

    No idea. Hopefully, JohnBF or someone else will have a suggestion.

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

    Re: writing Outlook macros (Win XP home)

    Robert, help us to help you by setting "Option Explicit" at the start of in the module, and seeing how the code runs then. There seem to be some undeclared variables and redundancies in your code, so it's hard to quickly see what is going on, and setting Option Explicit will force some discipline to the code structure.
    -John ... I float in liquid gardens
    UTC -7ąDS

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

    Re: writing Outlook macros (Win XP home)

    Ms. Mosher knows her stuff, but the following code is much simpler and should meet the objectives in your original post:

    Sub PDA()
    Dim newStore As MAPIFolder

    With Application.Session
    'Open, set, and name new PST
    .AddStore "M:F CoveyPDA_Sync.pst"
    Set newStore = .Folders.GetLast
    newStore.Name = "PDA Sync " & Format(Date, "yyyymmdd")
    'copy entire existing default contacts folder and entire existing default calendar to the new store
    .GetDefaultFolder(olFolderContacts).CopyTo newStore
    .GetDefaultFolder(olFolderCalendar).CopyTo newStore
    'Close new PST
    .RemoveStore newStore
    End With

    'Clean up
    Set newStore = Nothing
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  12. #12
    Star Lounger
    Join Date
    May 2003
    Location
    Whitmore Lake, MI , USA
    Posts
    84
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Re: writing Outlook macros (Win XP home)

    Option explicit? is that code to enter or a selection from the menu? Sorry to sound clueless, but...I am!

    The original code was a script called copypst2pst that someone posted on her site. I'm getting ready to test your offering to see how well it works. She offered a fix for the endless loop, but when it creates the file, it fails to copy everything/anything over, showing a file size of 256k when, if I export it by hand, the file is app. 736k.

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: writing Outlook macros (Win XP home)

    Insert the line

    Option Explicit

    at the very top of the module. When you run the code or select Debg | Compile <project>, you may see an error message about an undefined variable.

    You can have the line added automatically to new modules by ticking the check box "Require variable declaration" in Tools | Options in the Visual Basic Editor. See <post#=314,748>post 314,748</post#> for an explanation why that is important.

  14. #14
    Star Lounger
    Join Date
    May 2003
    Location
    Whitmore Lake, MI , USA
    Posts
    84
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Re: writing Outlook macros (Win XP home)

    That works perfectly! Now all I have to do is fidn the name of the folder for Franklin Covey's PlanPlus for Outlook and I'll be set. Thanks!

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

    Re: writing Outlook macros (Win XP home)

    For non-default folders, instead of the GetDefaultFolder Method, use:

    .Folders("Robert Personal Folders").Folders("Business").Folders("Franklin Covey").CopyTo newStore

    where "Robert Personal Folders" is the name of the Store, and the Folders have to be named in sequence for each subfolder in the folder path/tree.
    -John ... I float in liquid gardens
    UTC -7ąDS

Page 1 of 2 12 LastLast

Posting Permissions

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