Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Help please!
Using assistance from online resources I have VBA to create an Outlook contact from an Excel spreadsheet. I was told the machines it was to work on were Office 2016, the same as I use. When I took the macros on-site they use Outlook 2016 but Excel 2013; although one machine is all Office 2016. The macro worked on the "all office 2016" machine but gave an error of "Missing Microsoft Outlook 16.0 object library." I know I should use Late Binding for this, but can't get it to work/am not experienced enough. Having done extensive searches I found the article below (in quotes) and am wondering if I can take the file WITHOUT THE VBA in it to an Outlook 2013 machine, go into VBA Editor, check the Outlook 15.0 Library reference, paste in the VBA, save the document, then run the macro, it will have the correct DLL referred? This is an extract from the article that prompted this question:- "One way to deal with this is to create and save the workbook using the earlier version of Excel. When it is opened in the later version of Excel, the reference to the VBA library will be automatically updated. Excel does the updates going to later versions, but it doesn't do them going to earlier versions. This means, however, that even if the workbook is created in the earlier version of Excel, once it is opened and subsequently saved in the later version of Excel, users of the earlier version will have problems opening it." THE VBA CODE Sub ExcelWorksheetDataAddToOutlookContacts1() Application.ScreenUpdating = False If MsgBox("Have you checked if this client has an existing record with us?", vbQuestion + vbYesNo, "Input Question") < vbYes Then Exit Sub End If 'Automating Outlook from Excel: This example uses the Application.CreateItem Method to export data from an Excel Worksheet to the default Contacts folder. 'Automate using Early Binding: Add a reference to the Outlook Object Library in Excel (your host application) by clicking Tools-References in VBE, which will enable using Outlook's predefined constants. Once this reference is added, a new instance of Outlook application can be created by using the New keyword. 'Ensure that the worksheet data to be posted to Outlook, starts from row number 2: 'Ensure corresponding columns of data in the Worksheet, as they will be posted in the Outlook Contacts Folder: 'Column A: First Name 'Column B: Last Name 'Column C: Email Address 'Column D: Company Name 'Column E: Mobile Telephone Number Dim applOutlook As Outlook.Application Dim nsOutlook As Outlook.Namespace Dim ciOutlook As Outlook.ContactItem Dim delFolder As Outlook.folder Dim delItems As Outlook.Items Dim lLastRow As Long, i As Long, n As Long, c As Long 'determine last data row in the worksheet: lLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row 'Create a new instance of the Outlook application. Set the Application object as follows: Set applOutlook = New Outlook.Application 'use the GetNameSpace method to instantiate (ie. create an instance) a NameSpace object variable, to access existing Outlook items. Set the NameSpace object as follows: Set nsOutlook = applOutlook.GetNamespace("MAPI") '---------------------------- 'Empty the Deleted Items folder in Outlook so that when you quit the Outlook application you bypass the prompt: Are you sure you want to permanently delete all the items and subfolders in the "Deleted Items" folder? 'set the default Deleted Items folder: Set delFolder = nsOutlook.GetDefaultFolder(olFolderDeletedItems) 'set the items collection: Set delItems = delFolder.Items 'determine number of items in the collection: c = delItems.Count 'start deleting from the last item: For n = c To 1 Step -1 delItems(n).Delete Next n '---------------------------- 'post each row's data on a separate contact item form: For i = 2 To lLastRow 'Use the Application.CreateItem Method to create a new contact Outlook item in the default Contacts folder. Using this method a new contact item is always created in the default Contacts folder. 'create and display a new contact form for input: Set ciOutlook = applOutlook.CreateItem(olContactItem) 'display the new contact item form: ciOutlook.Display 'set properties of the new contact item: With ciOutlook ..firstName = Sheets("Sheet1").Cells(i, 1) ..LastName = Sheets("Sheet1").Cells(i, 2) ..JobTitle = Sheets("Sheet1").Cells(i, 3) ..Email1Address = Sheets("Sheet1").Cells(i, 4) ..CompanyName = Sheets("Sheet1").Cells(i, 5) ..BusinessTelephoneNumber = Sheets("Sheet1").Cells(i, 7) ..HomeTelephoneNumber = Sheets("Sheet1").Cells(i, 6) ..MobileTelephoneNumber = Sheets("Sheet1").Cells(i, 8) ..HomeAddress = Sheets("Sheet1").Cells(i, 9) ..Body = Sheets("Sheet1").Cells(i, 10) End With 'close the new contact item form after saving: ciOutlook.Close olSave Next i 'quit the Oulook application: 'applOutlook.Quit 'clear the variables: Set applOutlook = Nothing Set nsOutlook = Nothing Set ciOutlook = Nothing Set delFolder = Nothing Set delItems = Nothing MsgBox "Check in Outlook Contacts to make sure the record is created correctly", vbOK, "Question" Application.ScreenUpdating = True End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting correct MS Outlook Object Library (repeat) | Excel Programming | |||
Selecting correct MS Outlook Object Library | Excel Programming | |||
Microsoft Outlook Library | Excel Discussion (Misc queries) | |||
Microsoft Word Object Library in Excel | Excel Discussion (Misc queries) | |||
Outlook 11 Outlook 10 Object Library Compatibility Issues | Excel Programming |