Getting Outlook Data into Word

E

EHPorter

I am writing an address macro that addresses letters to various government
entities. It's quite simple (I'm new at this) and just presents the user
with a series of option buttons:

If Opt1 Then
Addressee = "Hennepin County"
AddressLine1 = "Government Center"

ElseIf Opt2 Then
Addressee = "Ramsey County"
AddressLine2 = "Courthouse West Annex"
.. . . and so forth. These are then inserted into the document using
bookmarks. The problem, of course, is that these addresses are already in
Outlook. Plus, every time a department changes its address, I need to
update both Outlook and the address Macro.

Is there a relatively simple way to extract this information directly from
an Outlook contacts folder, such that the address macro would always reflect
the correct address?

Thanks.
 
E

EHPorter

Thank you. I am having some success with the examples you provided. I do
have one problem, however. I have a lot of information stored in
sub-folders within the Outlook Contacts folder. All addresses for
departments in Ramsey County, Minnesota, for example, are stored in a
sub-folder called "Ramsey." How do I access these subfolders? Below is my
current test routine -- it accesses the main (default) Contacts folder and
just writes out a list of names and telephone numbers. How would I modify
the code to access a sub-folder?

Thank you.

****************Progress so far*********************

Private Sub GetOutlookInfo()

Dim oApp As Outlook.Application
Dim oNspc As NameSpace
Dim oItm As ContactItem
Dim ContactName As String
Dim FS As Object
Dim MyNewFile As Object


Set FS = CreateObject("Scripting.FileSystemObject")
Set MyNewFile = FS.CreateTextFile("c:\temp\testfile.txt", True)
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")

For Each oItm In oNspc.GetDefaultFolder _
(olFolderContacts).Items

ContactName = oItm.FullName
ContactName = ContactName + " " + oItm.BusinessTelephoneNumber
MyNewFile.writeline (ContactName)

Next oItm

MsgBox ("Script has run")

Set oItm = Nothing
Set oNspc = Nothing
Set oApp = Nothing
MyNewFile.Close

End Sub

******************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top