|
-
Mar 7th, 2006, 05:00 AM
#1
Thread Starter
Member
[Resolved] Export addresses from Excel to Outlook
Im writing a small function in VBA in Excell to create an Address book in Outlook 2003 from the list of staff names & addresses in an Excell spreadsheet.
It needs to be done this way as the software in use to store the staff details can only output to a .csv file.
Im thinking i have to do somthing along the lines of:
VB Code:
Dim oApp As Outlook.Application
Dim oAddress As Outlook.AddressList 'Is this correct?
Set oApp = New Outlook.Application
Set oAddress = 'Not entirely sure of how to assign this
And then read through each line of the spreadsheet creating entries?
Last edited by c03cg; Mar 7th, 2006 at 11:03 AM.
Reason: [Resolved]
-
Mar 7th, 2006, 07:56 AM
#2
Thread Starter
Member
Re: Export addresses from Excel to Outlook
ok, so sofar i can add a new contact with the needed details using:
VB Code:
Dim oApp As Outlook.Application
Dim oNS As Outlook.Namespace
Dim iOne As Integer
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Dim oContact As Outlook.ContactItem
'Set oContact = oNS.GetItemFromID(Range("B2") & " " & Range("A2"))
iOne = 1
Do While iOne < 200
Range("E" & iOne + 1).Select
ActiveCell.FormulaR1C1 = "=R[-1]C+1"
iOne = iOne + 1
Loop
Columns("E:E").Select
Selection.NumberFormat = "000"
Application.Cursor = xlWait
Set oContact = oApp.CreateItem(olContactItem)
oContact.CompanyName = "President Kennedy School"
oContact.Email1Address = Range("D2").Text
oContact.Email1AddressType = "Business"
oContact.Email1DisplayName = Range("B2").Text & " " & Range("A2").Text
oContact.FileAs = Range("A2").Text & ", " & Range("B2").Text
oContact.FirstName = Range("B2").Text
oContact.FullName = Range("B2").Text & " " & Range("A2").Text
oContact.LastName = Range("A2").Text
oContact.UserProperties("PKSID") = oContact.User1
oContact.User1 = "PKS" & Range("E2")
oContact.Save
Application.Cursor = xlDefault
I beleive ive set up 'User1' to add a field called PKSID and fill it with a 3 digit number..... how can i search the contacts by this so i dont duplicate?
-
Mar 7th, 2006, 07:59 AM
#3
Re: Export addresses from Excel to Outlook
Use the Restrict or Find methods. One of them is for use with custom properties. Cant remember right now.
Also, if you save the .EntryID property of the contact item that would be your unique ID throughout your Outlook store.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 7th, 2006, 08:19 AM
#4
Thread Starter
Member
Re: Export addresses from Excel to Outlook
Cheers for the advice Rob..... searching them atm..... but what outlook property do i have to search within?
-
Mar 7th, 2006, 08:21 AM
#5
Re: Export addresses from Excel to Outlook
The .Items collection of the MAPIFolder your creating or storing the contact items in.
If you use the .EntryID property you can also use the .GetItemFromID method of the NameSpace object class.[/color]
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 7th, 2006, 10:10 AM
#6
Thread Starter
Member
Re: Export addresses from Excel to Outlook
Cool.... its working, cheers RobDog, my code now looks like this:
VB Code:
Sub Create_Address_Book()
Dim oApp As Outlook.Application
Dim oNS As Outlook.Namespace
Dim oCF As Outlook.MAPIFolder
Dim iOne As Integer
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Dim oContact As Outlook.ContactItem
Set oCF = oNS.Folders(1).Folders("Contacts")
iOne = 2
Application.Cursor = xlWait
Do While Not Range("A" & iOne) = ""
Set oContact = oCF.Items.Find("[FullName] = " & Range("b" & iOne) & " " & Range("a" & iOne) & "")
If TypeName(oContact) = "Nothing" Then
Set oContact = oApp.CreateItem(olContactItem)
oContact.CompanyName = "President Kennedy School"
oContact.Email1Address = Range("D" & iOne).Text
oContact.Email1AddressType = "Business"
oContact.Email1DisplayName = Range("B" & iOne).Text & " " & Range("A" & iOne).Text
oContact.FileAs = Range("A" & iOne).Text & ", " & Range("B" & iOne).Text
oContact.FirstName = Range("B" & iOne).Text
oContact.FullName = Range("B" & iOne).Text & " " & Range("A" & iOne).Text
oContact.LastName = Range("A" & iOne).Text
oContact.Save
Else
Application.Cursor = xlDefault
MsgBox "The contact '" & oContact & "' already exists"
Application.Cursor = xlWait
End If
iOne = iOne + 1
Loop
Application.Cursor = xlDefault
End Sub
How do i change the Contacts view programaitically?
-
Mar 7th, 2006, 10:20 AM
#7
Re: Export addresses from Excel to Outlook
VB Code:
Set oApp.ActiveExplorer.CurrentFolder = oCF
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 7th, 2006, 10:39 AM
#8
Thread Starter
Member
Re: Export addresses from Excel to Outlook
Cheers... but, being the doofus i am, didn't explain what i meant!
How do i set the Contacts folder to 'View by Company' programatically?
-
Mar 7th, 2006, 10:51 AM
#9
Re: Export addresses from Excel to Outlook
Oh, . You need to modify the View manually. Then use the View object and Views collection for that folder to save it out to an xml or text file. Then when you run your app you can read in the file and set the view of your folder to that read-in saved xml view.
You can just change the xml element using the xml parse class but its more code then its worth when you can do it this was with just a few lines of code and no references.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 7th, 2006, 10:56 AM
#10
Thread Starter
Member
Re: Export addresses from Excel to Outlook
Spot on.... cheers Rob, im going to mark the matter resolved, however if i get stuck with it, ill post again and PM you
Many thanks
-
Mar 7th, 2006, 10:59 AM
#11
Re: Export addresses from Excel to Outlook
My inbox is almost full so as long as you post back to this thread I will get it since I subscribe to all threads I post to.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 9th, 2006, 05:25 AM
#12
Thread Starter
Member
Re: [Resolved] Export addresses from Excel to Outlook
RD.......
ive got this:
VB Code:
Sub viewCheck()
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oCF As Outlook.MAPIFolder
Dim oView As Outlook.View
Dim oviews As Outlook.Views
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oCF = oNS.Folders(1).Folders("Contacts")
Set oView = oCF.CurrentView
Set oviews = oCF.Views
MsgBox oView.XML
End Sub
which obvioulsy displays the XML in a msgbox, how do i get Excell to set outlook to this view? The view name is 'By Company' and its a standard outlook one
Any ideas?
-
Mar 9th, 2006, 05:37 AM
#13
Re: [Resolved] Export addresses from Excel to Outlook
You mean to just change the view or customize it?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 9th, 2006, 05:43 AM
#14
Thread Starter
Member
Re: [Resolved] Export addresses from Excel to Outlook
Just change it from the default view to the 'By Company' view
-
Mar 9th, 2006, 05:45 AM
#15
Re: [Resolved] Export addresses from Excel to Outlook
Oh, ok. Thats easier. I think this is it.
VB Code:
'...
'...
Set oViews = oTaskBox.Views
Set oView = oViews.Item("By Company")
'Set the view to the current view
oView.Save
oView.Apply
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 9th, 2006, 05:53 AM
#16
Thread Starter
Member
Re: [Resolved] Export addresses from Excel to Outlook
Good lad! Worked like a charm........ set oCF (current folder) to the contacts folder, then did:
VB Code:
Set oViews = oCF.Views
Set oView = oViews.Item("By Company")
oView.Save
oView.Apply
Many thanks again!
-
Mar 9th, 2006, 06:09 AM
#17
Re: [Resolved] Export addresses from Excel to Outlook
No prob.
I guess I still got it as I did it from memory and typed it into the reply box without testing (whew, glad it worked on first try lol).
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|