Hi Guys,
I have following queries regarding Outlook 2007 contact management .I am trying to export excel format using the following code to outlook 2007,contacts list, but its not working ..can someone assist me in sorting this out ..i am attaching the format i need to export and here is the code i am usingI have posted the same query on the following link as well: http://forums.techguy.org/business-a...ml#post7797407Dim appOutlook As Outlook.Application Dim objNameSpace As Outlook.Namespace Dim objContactFolder As Outlook.MAPIFolder Dim objContacts As Outlook.ContactItem 'Dim myDistList As Outlook.DistListItem Sub ContList() Set appOutlook = GetObject(, "Outlook.Application") Set objNameSpace = appOutlook.GetNamespace("MAPI") Set objContactFolder = objNameSpace.GetDefaultFolder(olFolderContacts) Set myMailItem = appOutlook.CreateItem(olMailItem) Set myRecipients = myMailItem.Recipients 'Set myDistList = appOutlook.CreateItem(olDistributionListItem) For i = 3 To Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row Set objContacts = objContactFolder.Items.Add(olContactItem) With objContacts '.Secs = Range("B" & i).Value '.CompanyName = Range("B" & i).Value .BusinessName = Range("C" & i).Value '.LastName = Range("C" & i).Value .ContactName = Range("D" & i).Value '.FirstName = Range("D" & i).Value .Custemail = Range("E" & i).Value '.BusinessAddress = Range("E" & i).Value .Traderemail = Range("F" & i).Value '.BusinessAddressCity = Range("F" & i).Value .salesemail = Range("G" & i).Value '.BusinessAddressState = Range("G" & i).Value .BusinessAddressPostalCode = Range("H" & i).Value .BusinessAddressCountry = Range("I" & i).Value .JobTitle = Range("J" & i).Value .BusinessTelephoneNumber = Range("K" & i).Value .BusinessFaxNumber = Range("L" & i).Value .Email1Address = Range("E:G" & i).Value '.Email1Address = Range("M" & i).Value .Body = Range("N" & i).Value .Save End With myRecipients.Add (Range("E" & i).Value) Next myRecipients.ResolveAll myDistList.AddMembers myRecipients myDistList.Display End Sub
Regards
Nutti ,nice to see you .
First , when you play it with outlook and macro's > the references !! Microsoft Outlook 12.0 Object library ( for outlook 2007 , 14.0 is 2010 )
second , do not change the the header names .
third , i'm test it with this part of your code .
look to the jpeg .( my outlook is Dutch ) but you can see the data .
When you will test it , do it with 4 a 5 customers , if it's wrong >>>> clean up your contacts in outlook ( max . 5 people )
Sub ContList() Dim appOutlook As Outlook.Application Dim objNameSpace As Outlook.Namespace Dim objContactFolder As Outlook.MAPIFolder Dim objContacts As Outlook.ContactItem Dim myDistList As Outlook.DistListItem Set appOutlook = GetObject(, "Outlook.Application") Set objNameSpace = appOutlook.GetNamespace("MAPI") Set objContactFolder = objNameSpace.GetDefaultFolder(olFolderContacts) Set myMailItem = appOutlook.CreateItem(olMailItem) Set myRecipients = myMailItem.Recipients Set myDistList = appOutlook.CreateItem(olDistributionListItem) For i = 3 To Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row Set objContacts = objContactFolder.Items.Add(olContactItem) With objContacts .CompanyName = Range("B" & i).Value .LastName = Range("C" & i).Value .FirstName = Range("D" & i).Value .BusinessAddress = Range("E" & i).Value .BusinessAddressCity = Range("F" & i).Value .BusinessAddressState = Range("G" & i).Value .BusinessAddressPostalCode = Range("H" & i).Value .BusinessAddressCountry = Range("I" & i).Value .JobTitle = Range("J" & i).Value .BusinessTelephoneNumber = Range("K" & i).Value .BusinessFaxNumber = Range("L" & i).Value .Email1Address = Range("M" & i).Value .Body = Range("N" & i).Value .Save End With 'myRecipients.Add (Range("E" & i).Value) Next myRecipients.ResolveAll myDistList.AddMembers myRecipients 'myDistList.Display End Sub
Hey T,
When I am tryin to run the code I am gettin error in..Runtime error 1004 ..For i = 3 To Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
2/ Do i have to update the contact list to a specefic format
3/ How to decide which code is to be run in outlook as I am confused ..
I ran this code in outlook ...Hey wat are ur plan for the week ends ..
awaiting inputs
Regards
Hoi Nutty , weekend is restI'll post an example .
when you start to search , into the second row then in the macro ( For i = 2 To Cells.Find ) if you start on row six >> then ( For i = 6 To Cells.Find )
Only run the code in the Excel Workbook
I post a quick example of how it can ( " Dutch sheets and text " ) , but i go to bed .
Take a look to the code
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks