tlman12 Posted April 5, 2013 Share Posted April 5, 2013 (edited) I had a need to write a script that would parse a VCF 3.0 file and put the contacts from a phone into a form that would be understood by outlook (csv). outlook does not have the ability to import VCF files where there are more then one contact and there wasn't anything out there that was free that would perform this simple task. I followed the specs of a VCF version 3.0 file structure, so most features should work, some will not. I only provide this script as a working example for reference. I'm not going to be providing updates and only minor troubleshooting, so if you make modifications and or fix something yourself please post it back here so other users can gain from it. what it does is parse the VCF file looking for certain tags. splits the string into its possible components and matches them up to the correct column in outlook. after the contact is fully parsed (between the begin vcard tag and the end vcard tag) a line is written in the proper format to the CSV file as well as the contact being imported directly to your contacts list. the script does a very basic first name last name check to see if you are importing duplicates which you can choose to allow or not allow the script normalizes the name (in case the phone did not save it properly. some phones will export the full name attribute not the firstname lastname so i have it making that the contact name or if there is no name the contact name becomes the e-mail. this can be tweaked to your liking. this script also will run as and import contacts into another users outlook (if thats something you need) if not you can just remove it. once finished the script also copies the VCF from it's original location to the location of the CSV for backup purposes and then sticks a copy of the CSV into the mailbox of the user (because I can ) I'm sharing this script mainly because it is a great example of file parsing, and outlook integration that isn't always so well documented. expandcollapse popupOpt("WinTitleMatchMode", 2) Dim $importDups = False If $cmdLine[0] = "" Then If ProcessExists("outlook.exe") Then MsgBox(64, "Important", "In order for this to work correctly you will have to close you outlook. Please close outlook and click OK to continue") If ProcessExists("outlook.exe") Then Exit EndIf EndIf $usr = InputBox("UserName", "Please type the users username") If $usr = "" Then Exit $pass = InputBox("Password", "Please type the users Password", "", "*") If $pass = "" Then Exit $pid = RunAs($usr, "domain", $pass, 1, @ScriptFullPath & ' cmd') If $pid = 0 Then DirCreate("C:\temp") $a = FileCopy(@ScriptFullPath,"C:\temp",1) If $a Then $pid = RunAs($usr, "domain", $pass, 1, "C:\temp\" & @ScriptName & ' cmd') If $pid = 0 Then MsgBox(16,"Error","There was an error running as the user. Check the password and/or try copying the exe to the temp folder on your computer and running it again.") Else While ProcessExists($pid) Sleep(500) WEnd FileDelete("C:\temp\" & @ScriptName) EndIf EndIf Else If FileExists("C:\Program Files\Microsoft Office\Office15\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office15\Outlook.exe" ElseIf FileExists("C:\Program Files\Microsoft Office\Office14\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office14\Outlook.exe" ElseIf FileExists("C:\Program Files\Microsoft Office\Office13\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office13\Outlook.exe" ElseIf FileExists("C:\Program Files\Microsoft Office\Office12\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office12\Outlook.exe" EndIf Run($path) While ProcessExists("Outlook.exe") If WinActive("Welcome to Microsoft Outlook", "") Then MsgBox(64, "Important", "It appears that you will need to get the user configured to use outlook. Please run through the configuration and click ok to continue") While WinActive("Welcome to Microsoft Outlook", "") MsgBox(64, "...", "I told you to set up the user first.. :)") WEnd EndIf If Not WinActive("Welcome to Microsoft Outlook", "") Then WinActivate("Welcome to Microsoft Outlook", "") Sleep(500) If Not WinActive("Welcome to Microsoft Outlook", "") Then ExitLoop EndIf WEnd If Not ProcessExists("Outlook.exe") Then Exit Dim $csv_fn, $csv_mn, $csv_ln, $csv_title, $csv_suf, $csv_Mobile, $csv_initials, $csv_Webp, $csv_Gen, $csv_Birth, $csv_Ann, $csv_loc, $csv_lang, $csv_intFB, $csv_Notes, $csv_Eml1, $csv_Eml2, $csv_Eml3, $csv_Eml4, $csv_PriPhone, $csv_hPhone, $csv_hPhone2, $csv_MPhone, $csv_Pager, $csv_hFax, $csv_hAddress, $csv_hStreet, $csv_hStreet2, $csv_hStreet3, $csv_hPOBox, $csv_hCity, $csv_hState, $csv_hZip, $csv_hCountry, $csv_Spouse, $csv_Children, $csv_ManagersName, $csv_AssistantsName, $csv_RefferedBy, $csv_CompPhone, $csv_BusiPhone, $csv_BusiPhone2, $csv_BusiFax, $csv_AssistantsPhone, $csv_Company, $csv_JobTitle, $csv_Department, $csv_OfficeLocation, $csv_OrgIDNumber, $csv_Profession, $csv_Account, $csv_BusiAddress, $csv_BusiStreet, $csv_BusiStreet2, $csv_BusiStreet3, $csv_BusiPOBox, $csv_BusiCity, $csv_BusiState, $csv_BusiZip, $csv_BusiCountry, $csv_OtherPhone, $csv_OtherFax, $csv_OtherAddress, $csv_OtherStreet, $csv_OtherStreet2, $csv_OtherStreet3, $csv_OtherPOBox, $csv_OtherCity, $csv_OtherZip, $csv_OtherCountry, $csv_Callback, $csv_CarPhone, $csv_RadioPhone, $csv_TTYPhone, $csv_Telex, $csv_User1, $csv_User2, $csv_User3, $csv_User4, $csv_Keywords, $csv_Mialage, $csv_Hobby, $csv_BillingInfo, $csv_DirectoryServer, $csv_Sensitivity, $csv_Private, $csv_Categories Dim $csv_FullName Dim $csv_FirstLine = "First Name,Middle Name,Last Name,Title,Suffix,Mobile Phone,Initials,Web Page,Gender,Birthday,Anniversary,Location,Language,Internet Free Busy,Notes,E-mail 1 Address,E-mail 2 Address,E-mail 3 Address,E-mail 4 Address,Primary Phone,Home Phone,Home Phone 2,Mobile Phone,Pager,Home Fax,Home Address,Home Street,Home Street 2,Home Street 3,Home Address PO Box,Home City,Home State,Home Postal Code,Home Country,Spouse,Children,Manager's Name,Assistant's Name,Referred By,Company Main Phone,Business Phone,Business Phone 2,Business Fax,Assistant's Phone,Company,Job Title,Department,Office Location,Organizational ID Number,Profession,Account,Business Address,Business Street,Business Street 2,Business Street 3,Business Address PO Box,Business City,Business State,Business Postal Code,Business Country,Other Phone,Other Fax,Other Address,Other Street,Other Street 2,Other Street 3,Other Address PO Box,Other City,Other State,Other Postal Code,Other Country,Callback,Car Phone,ISDN,Radio Phone,TTY/TDD Phone,Telex,User 1,User 2,User 3,User 4,Keywords,Mileage,Hobby,Billing Information,Directory Server,Sensitivity,Priority,Private,Categories" _BlankOut() ;Get File $vcf = FileOpenDialog("Find VCF File", @ScriptDir, "VCF (*.vcf)", 3) If $vcf = "" Then Exit $x = 0 $o_vcf = FileOpen($vcf, 0) Do $x += 1 $line = FileReadLine($o_vcf, $x) Until $line = "BEGIN:VCARD" Or @error If @error Then MsgBox(16, "Error", "Couldn't find VCARD tag. Make sure that you are specifying a valid VCF file and that the file is accessable (readable).") Exit EndIf DirCreate("C:\temp") DirCreate("C:\temp\OutlookCSV") $csv = FileSaveDialog("CSV File","C:\temp\OutlookCSV","CSV (*.csv)",18,"OutlookCSV_" & @UserName & "." & @MON & "." & @MDAY & "." & @YEAR & ".csv") If $csv = "" Then Exit FileCopy($vcf,"C:\temp\OutlookCSV\PhoneVCF_" & @UserName & "." & @MON & "." & @MDAY & "." & @YEAR & ".vcf",1) If FileExists($csv) Then $tmp = FileDelete($csv) If $tmp Then $o_csv = FileOpen($csv, 1) Else MsgBox(16, "Error", "Could not over write previous File. maybe it's open in another program?") Exit EndIf Else $o_csv = FileOpen($csv, 1) EndIf FileWriteLine($o_csv, $csv_FirstLine) $msg = MsgBox(3+32+256,"Ready","I'm ready to start, just one more question. Would you like to import Contacts deemed to be duplicates? (A contact will be deemed duplicate if the FirstName and LastName match exactly).") Switch $msg Case 6 $importDups = True Case 7 $importDups = False Case 2 Exit EndSwitch If StringInStr(FileReadLine($o_vcf, $x), "BEGIN:VCARD") Then If StringInStr(FileReadLine($o_vcf, $x + 1), "VERSION:3.0") Then While 1 Do $x += 1 $line = FileReadLine($o_vcf, $x) $data = StringSplit($line, ";:", 2) Switch $data[0] Case "N" If UBound($data) >= 3 Then $csv_fn = $data[2] If UBound($data) >= 2 Then $csv_ln = $data[1] If UBound($data) >= 4 Then $csv_mn = $data[3] If UBound($data) >= 5 Then $csv_title = $data[4] Case "ADR" Switch $data[1] Case "TYPE=WORK" If $csv_BusiPOBox <> "" Or $csv_BusiAddress <> "" Or $csv_BusiStreet <> "" Or $csv_BusiCity <> "" Or $csv_BusiState <> "" Or $csv_BusiZip <> "" Or $csv_BusiCountry <> "" Then MsgBox(16, "Error", "Work address already recorded for this contact, sorry I only support 1. script will continue but address will not be moved") Else If UBound($data) = 3 Then $csv_BusiPOBox = $data[2] If UBound($data) = 4 Then $csv_BusiAddress = $data[3] If UBound($data) = 5 Then $csv_BusiStreet = $data[4] If UBound($data) = 6 Then $csv_BusiCity = $data[5] If UBound($data) = 7 Then $csv_BusiState = $data[6] If UBound($data) = 8 Then $csv_BusiZip = $data[7] If UBound($data) = 9 Then $csv_BusiCountry = $data[8] EndIf Case "TYPE=HOME" If $csv_hPOBox <> "" Or $csv_hAddress <> "" Or $csv_hStreet <> "" Or $csv_hCity <> "" Or $csv_hState <> "" Or $csv_hZip <> "" Or $csv_hCountry <> "" Then MsgBox(16, "Error", "Home address already recorded for this contact, sorry I only support 1. script will continue but address will not be moved") Else If UBound($data) = 3 Then $csv_hPOBox = $data[2] If UBound($data) = 4 Then $csv_hAddress = $data[3] If UBound($data) = 5 Then $csv_hStreet = $data[4] If UBound($data) = 6 Then $csv_hCity = $data[5] If UBound($data) = 7 Then $csv_hState = $data[6] If UBound($data) = 8 Then $csv_hZip = $data[7] If UBound($data) = 9 Then $csv_hCountry = $data[8] EndIf EndSwitch Case "BDAY" If UBound($data) > 1 Then $csv_Birth = StringReplace(StringMid($data[1], 5, 2), "0", "") & "/" & StringReplace(StringMid($data[1], 7, 2), "0", "") & "/" & StringMid($data[1], 1, 4) Case "CATEGORIES" If UBound($data) > 1 Then $csv_Categories = $data[1] Case "CLASS" If UBound($data) > 1 Then $csv_Private = $data[1] Case "EMAIL" If $csv_Eml1 <> "" And $csv_Eml2 <> "" And $csv_Eml3 <> "" And $csv_Eml4 <> "" Then MsgBox(16, "Error", "All E-mail slots have been used, no more e-mails will be processed for this contact") Else Switch $data[1] Case "TYPE=PREF" If UBound($data) = 3 Then $csv_Eml1 = $data[2] ElseIf UBound($data) = 4 Then $csv_Eml1 = $data[3] EndIf Case Else If UBound($data) > 1 Then If UBound($data) = 3 Then $tmp = $data[2] ElseIf UBound($data) = 4 Then $tmp = $data[3] ElseIf UBound($data) = 2 Then $tmp = $data[1] EndIf If $csv_Eml2 <> "" Then If $csv_Eml3 <> "" Then $csv_Eml4 = $tmp Else $csv_Eml3 = $tmp EndIf Else $csv_Eml2 = $tmp EndIf EndIf EndSwitch EndIf Case "FN" If UBound($data) = 2 Then $csv_FullName = $data[1] Case "LABEL" If UBound($data) = 2 Then $csv_Notes = $csv_Notes & $data[1] & "\n \n" If UBound($data) = 3 Then $csv_Notes = $csv_Notes & $data[2] & "\n \n" Case "NOTE" If UBound($data) = 2 Then $csv_Notes = $csv_Notes & $data[1] & "\n \n" Case "ORG" If UBound($data) >= 2 Then For $z = 1 To UBound($data) - 1 $csv_Company = $csv_Company & " " & $data[$z] Next EndIf Case "PHOTO" ;can't import into outlook Case "TITLE" If UBound($data) = 2 Then $csv_JobTitle = $data[1] Case "URL" If UBound($data) = 2 Then $csv_Webp = $data[1] Case "TEL" If $csv_Mobile <> "" And $csv_hPhone <> "" And $csv_hPhone2 <> "" And $csv_BusiPhone <> "" And $csv_BusiPhone2 <> "" Then ;All phone numbers have been used for Exces numbers will be put into the Notes Section (May be out of order) $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else Switch $data[1] Case "TYPE=CELL" If $csv_Mobile <> "" Then $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else $csv_Mobile = $data[2] EndIf Case "TYPE=WORK" If $csv_BusiPhone <> "" Then If $csv_BusiPhone2 <> "" Then $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else $csv_BusiPhone2 = $data[2] EndIf Else $csv_BusiPhone = $data[2] EndIf Case "TYPE=HOME" If $csv_hPhone <> "" Then If $csv_hPhone2 <> "" Then $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else $csv_hPhone2 = $data[2] EndIf Else $csv_hPhone = $data[2] EndIf Case Else $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" EndSwitch EndIf EndSwitch Until $line = "END:VCARD" $line = FileReadLine($o_vcf, $x + 1) If $csv_fn = "" Then If $csv_ln = "" Then If $csv_FullName = "" Then If $csv_Eml1 = "" Then If $csv_Eml2 = "" Then ;do nothing Else $csv_fn = $csv_Eml2 EndIf Else $csv_fn = $csv_Eml1 EndIf Else $csv_fn = $csv_FullName EndIf Else $csv_fn = $csv_ln EndIf EndIf FileWriteLine($o_csv, $csv_fn & "," & $csv_mn & "," & $csv_ln & "," & $csv_title & "," & $csv_suf & "," & $csv_Mobile & "," & $csv_initials & "," & $csv_Webp & "," & $csv_Gen & "," & $csv_Birth & "," & $csv_Ann & "," & $csv_loc & "," & $csv_lang & "," & $csv_intFB & "," & $csv_Notes & "," & $csv_Eml1 & "," & $csv_Eml2 & "," & $csv_Eml3 & "," & $csv_Eml4 & "," & $csv_PriPhone & "," & $csv_hPhone & "," & $csv_hPhone2 & "," & $csv_MPhone & "," & $csv_Pager & "," & $csv_hFax & "," & $csv_hAddress & "," & $csv_hStreet & "," & $csv_hStreet2 & "," & $csv_hStreet3 & "," & $csv_hPOBox & "," & $csv_hCity & "," & $csv_hState & "," & $csv_hZip & "," & $csv_hCountry & "," & $csv_Spouse & "," & $csv_Children & "," & $csv_ManagersName & "," & $csv_AssistantsName & "," & $csv_RefferedBy & "," & $csv_CompPhone & "," & $csv_BusiPhone & "," & $csv_BusiPhone2 & "," & $csv_BusiFax & "," & $csv_AssistantsPhone & "," & $csv_Company & "," & $csv_JobTitle & "," & $csv_Department & "," & $csv_OfficeLocation & "," & $csv_OrgIDNumber & "," & $csv_Profession & "," & $csv_Account & "," & $csv_BusiAddress & "," & $csv_BusiStreet & "," & $csv_BusiStreet2 & "," & $csv_BusiStreet3 & "," & $csv_BusiPOBox & "," & $csv_BusiCity & "," & $csv_BusiState & "," & $csv_BusiZip & "," & $csv_BusiCountry & "," & $csv_OtherPhone & "," & $csv_OtherFax & "," & $csv_OtherAddress & "," & $csv_OtherStreet & "," & $csv_OtherStreet2 & "," & $csv_OtherStreet3 & "," & $csv_OtherPOBox & "," & $csv_OtherCity & "," & $csv_OtherZip & "," & $csv_OtherCountry & "," & $csv_Callback & "," & $csv_CarPhone & "," & $csv_RadioPhone & "," & $csv_TTYPhone & "," & $csv_Telex & "," & $csv_User1 & "," & $csv_User2 & "," & $csv_User3 & "," & $csv_User4 & "," & $csv_Keywords & "," & $csv_Mialage & "," & $csv_Hobby & "," & $csv_BillingInfo & "," & $csv_DirectoryServer & "," & $csv_Sensitivity & "," & $csv_Private & "," & $csv_Categories) $oOutlook = ObjCreate("Outlook.Application") If $importDups Then $doIt = True Else $doIt = SearchContact($csv_fn,$csv_ln,$oOutlook) EndIf If $doIt Then $contactitem = $oOutlook.CreateItem(2) $contactitem.FirstName = $csv_fn $contactitem.MiddleName = $csv_mn $contactitem.LastName = $csv_ln $contactitem.Title = $csv_title $contactitem.Suffix = $csv_suf $contactitem.MobileTelephoneNumber = $csv_Mobile $contactitem.Initials = $csv_initials $contactitem.PersonalHomePage = $csv_Webp ;~ $contactitem.Gender = "" If Not $csv_Birth = "0/0/00" Then $contactitem.Birthday = $csv_Birth If Not $csv_Ann = "0/0/00" Then $contactitem.Anniversary = $csv_Ann $contactitem.OfficeLocation = $csv_loc $contactitem.Language = $csv_lang $contactitem.InternetFreeBusyAddress = $csv_intFB $contactitem.Body = $csv_Notes $contactitem.Email1Address = $csv_Eml1 $contactitem.Email2Address = $csv_Eml2 $contactitem.Email3Address = $csv_Eml3 ;~ $contactitem.= $csv_Eml4 $contactitem.PrimaryTelephoneNumber = $csv_PriPhone $contactitem.HomeTelephoneNumber = $csv_hPhone $contactitem.Home2TelephoneNumber = $csv_hPhone2 $contactitem.MobileTelephoneNumber = $csv_MPhone $contactitem.PagerNumber = $csv_Pager $contactitem.HomeFaxNumber = $csv_hFax $contactitem.HomeAddress = $csv_hAddress $contactitem.HomeAddressStreet = $csv_hStreet ;~ $contactitem.= $csv_hStreet2 ;~ $contactitem.= $csv_hStreet3 $contactitem.HomeAddressPostOfficeBox = $csv_hPOBox $contactitem.HomeAddressCity = $csv_hCity $contactitem.HomeAddressState = $csv_hState $contactitem.HomeAddressPostalCode = $csv_hZip $contactitem.HomeAddressCountry = $csv_hCountry $contactitem.Spouse = $csv_Spouse $contactitem.Children = $csv_Children $contactitem.ManagerName = $csv_ManagersName $contactitem.AssistantName = $csv_AssistantsName ;~ $contactitem.= $csv_RefferedBy $contactitem.CompanyMainTelephoneNumber = $csv_CompPhone $contactitem.BusinessTelephoneNumber = $csv_BusiPhone $contactitem.Business2TelephoneNumber = $csv_BusiPhone2 $contactitem.BusinessFaxNumber = $csv_BusiFax $contactitem.AssistantTelephoneNumber = $csv_AssistantsPhone $contactitem.Companies = $csv_Company $contactitem.JobTitle = $csv_JobTitle $contactitem.Department = $csv_Department $contactitem.OfficeLocation = $csv_OfficeLocation $contactitem.OrganizationalIDNumber = $csv_OrgIDNumber $contactitem.Profession = $csv_Profession $contactitem.Account = $csv_Account $contactitem.BusinessAddress = $csv_BusiAddress $contactitem.BusinessAddressStreet = $csv_BusiStreet ;~ $contactitem.= $csv_BusiStreet2 ;~ $contactitem.= $csv_BusiStreet3 $contactitem.BusinessAddressPostOfficeBox = $csv_BusiPOBox $contactitem.BusinessAddressCity = $csv_BusiCity $contactitem.BusinessAddressState = $csv_BusiState $contactitem.BusinessAddressPostalCode = $csv_BusiZip $contactitem.BusinessAddressCountry = $csv_BusiCountry $contactitem.OtherTelephoneNumber = $csv_OtherPhone $contactitem.OtherFaxNumber = $csv_OtherFax $contactitem.OtherAddress = $csv_OtherAddress $contactitem.OtherAddressStreet = $csv_OtherStreet ;~ $contactitem.= $csv_OtherStreet2 ;~ $contactitem.= $csv_OtherStreet3 $contactitem.OtherAddressPostOfficeBox = $csv_OtherPOBox $contactitem.OtherAddressCity = $csv_OtherCity $contactitem.OtherAddressPostalCode = $csv_OtherZip $contactitem.OtherAddressCountry = $csv_OtherCountry $contactitem.CallbackTelephoneNumber = $csv_Callback $contactitem.CarTelephoneNumber = $csv_CarPhone $contactitem.RadioTelephoneNumber = $csv_RadioPhone $contactitem.TTYTDDTelephoneNumber = $csv_TTYPhone $contactitem.TelexNumber = $csv_Telex $contactitem.User1 = $csv_User1 $contactitem.User2 = $csv_User2 $contactitem.User3 = $csv_User3 $contactitem.User4 = $csv_User4 ;~ $contactitem.= $csv_Keywords $contactitem.Mileage = $csv_Mialage $contactitem.Hobby = $csv_Hobby $contactitem.BillingInformation = $csv_BillingInfo $contactitem.NetMeetingServer = $csv_DirectoryServer ;~ $contactitem. = $csv_Sensitivity ;~ $contactitem.= $csv_Private ;~ $contactitem.= $csv_Categories $contactitem.Close(0) EndIf _BlankOut() If $line = "" Then ExitLoop WEnd FileClose($o_csv) FileClose($o_vcf) $oOutlook.CopyFile($csv, "Inbox") MsgBox(64,"Done!","If you are seeing this message the utility has completed with no errors. Check to see that the contacts are imported properly.") Else MsgBox(16, "Correct but no", "What you have here is a Vcard of the incorrect version, sorry.. at this time I'm only supporting 3.0") Exit EndIf Else MsgBox(16, "Error", "This does not appear to be a correct vcard file") Exit EndIf EndIf Func SearchContact($inFirst, $inLast, ByRef $oOutlook) ;~ 'activate Microsoft Outlook xx.x Object Library Dim $Cible Dim $dossierContacts $sFilter = "[FirstName] = " & Chr(34) & $inFirst & Chr(34) $namespace = $oOutlook.GetNamespace("MAPI") $dossierContacts = $namespace.GetDefaultFolder(10) $Cible = $dossierContacts.Items.Find($sFilter) If IsObj($Cible) Then If $Cible.LastName = $inLast Then Return False Else Return True EndIf Else Return True EndIf EndFunc ;==>SearchContact Func _BlankOut() $csv_fn = "" $csv_mn = "" $csv_ln = "" $csv_title = "" $csv_suf = "" $csv_Mobile = "" $csv_initials = "" $csv_Webp = "" $csv_Gen = "" $csv_Birth = "0/0/00" $csv_Ann = "0/0/00" $csv_loc = "" $csv_lang = "" $csv_intFB = "" $csv_Notes = "" $csv_Eml1 = "" $csv_Eml2 = "" $csv_Eml3 = "" $csv_Eml4 = "" $csv_PriPhone = "" $csv_hPhone = "" $csv_hPhone2 = "" $csv_MPhone = "" $csv_Pager = "" $csv_hFax = "" $csv_hAddress = "" $csv_hStreet = "" $csv_hStreet2 = "" $csv_hStreet3 = "" $csv_hPOBox = "" $csv_hCity = "" $csv_hState = "" $csv_hZip = "" $csv_hCountry = "" $csv_Spouse = "" $csv_Children = "" $csv_ManagersName = "" $csv_AssistantsName = "" $csv_RefferedBy = "" $csv_CompPhone = "" $csv_BusiPhone = "" $csv_BusiPhone2 = "" $csv_BusiFax = "" $csv_AssistantsPhone = "" $csv_Company = "" $csv_JobTitle = "" $csv_Department = "" $csv_OfficeLocation = "" $csv_OrgIDNumber = "" $csv_Profession = "" $csv_Account = "" $csv_BusiAddress = "" $csv_BusiStreet = "" $csv_BusiStreet2 = "" $csv_BusiStreet3 = "" $csv_BusiPOBox = "" $csv_BusiCity = "" $csv_BusiState = "" $csv_BusiZip = "" $csv_BusiCountry = "" $csv_OtherPhone = "" $csv_OtherFax = "" $csv_OtherAddress = "" $csv_OtherStreet = "" $csv_OtherStreet2 = "" $csv_OtherStreet3 = "" $csv_OtherPOBox = "" $csv_OtherCity = "" $csv_OtherZip = "" $csv_OtherCountry = "" $csv_Callback = "" $csv_CarPhone = "" $csv_RadioPhone = "" $csv_TTYPhone = "" $csv_Telex = "" $csv_User1 = "" $csv_User2 = "" $csv_User3 = "" $csv_User4 = "" $csv_Keywords = "" $csv_Mialage = "" $csv_Hobby = "" $csv_BillingInfo = "" $csv_DirectoryServer = "" $csv_Sensitivity = "" $csv_Private = "" $csv_Categories = "" EndFunc ;==>_BlankOut Edited April 5, 2013 by tlman12 Link to comment Share on other sites More sharing options...
water Posted April 5, 2013 Share Posted April 5, 2013 For all Outlook functions (start, import data etc.) you can use my OutlookEX UDF. Earthshine 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
tlman12 Posted April 5, 2013 Author Share Posted April 5, 2013 For all Outlook functions (start, import data etc.) you can use my OutlookEX UDF. you know.. i didn't even think to look for a UDF. i didn't start out with a plan of integrating with outlook so by the time i started doing it i just read teh MSDN documentation on the object. I just downloaded it though. good stuff. i will definitely use it next time i have to manipulate outlook. Thank you also i commented this script to make it a little easier to see what i did and why i did it. expandcollapse popupOpt("WinTitleMatchMode", 2) Dim $importDups = False ;Check command line to see if it's being run as another user If $cmdLine[0] = "" Then ;make sure outlook is closed If ProcessExists("outlook.exe") Then MsgBox(64, "Important", "In order for this to work correctly you will have to close you outlook. Please close outlook and click OK to continue") If ProcessExists("outlook.exe") Then Exit EndIf EndIf ;get username and password $usr = InputBox("UserName", "Please type the users username") If $usr = "" Then Exit $pass = InputBox("Password", "Please type the users Password", "", "*") If $pass = "" Then Exit ;re-run with new creds, add errounous command to continue script $pid = RunAs($usr, "domain", $pass, 1, @ScriptFullPath & ' cmd') If $pid = 0 Then ;run failed copy locally ;make sure c:\temp exists DirCreate("C:\temp") $a = FileCopy(@ScriptFullPath,"C:\temp",1) ;try to run again If $a Then $pid = RunAs($usr, "domain", $pass, 1, "C:\temp\" & @ScriptName & ' cmd') If $pid = 0 Then MsgBox(16,"Error","There was an error running as the user. Check the password and/or try copying the exe to the temp folder on your computer and running it again.") Else While ProcessExists($pid) Sleep(500) WEnd FileDelete("C:\temp\" & @ScriptName) EndIf EndIf Else ;find out what verson of outlook to use (the easy way) If FileExists("C:\Program Files\Microsoft Office\Office15\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office15\Outlook.exe" ElseIf FileExists("C:\Program Files\Microsoft Office\Office14\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office14\Outlook.exe" ElseIf FileExists("C:\Program Files\Microsoft Office\Office13\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office13\Outlook.exe" ElseIf FileExists("C:\Program Files\Microsoft Office\Office12\Outlook.exe") Then $path = "C:\Program Files\Microsoft Office\Office12\Outlook.exe" EndIf ;run outlook Run($path) ;loop until outlook window appears While ProcessExists("Outlook.exe") ;see if profile needs to be setup If WinActive("Welcome to Microsoft Outlook", "") Then MsgBox(64, "Important", "It appears that you will need to get the user configured to use outlook. Please run through the configuration and click ok to continue") While WinActive("Welcome to Microsoft Outlook", "") MsgBox(64, "...", "I told you to set up the user first.. :)") WEnd EndIf ;find window and bring it up front If Not WinActive("Welcome to Microsoft Outlook", "") Then WinActivate("Welcome to Microsoft Outlook", "") Sleep(500) If Not WinActive("Welcome to Microsoft Outlook", "") Then ExitLoop EndIf WEnd ;if outlook closed exit script If Not ProcessExists("Outlook.exe") Then Exit ;define variables Dim $csv_fn, $csv_mn, $csv_ln, $csv_title, $csv_suf, $csv_Mobile, $csv_initials, $csv_Webp, $csv_Gen, $csv_Birth, $csv_Ann, $csv_loc, $csv_lang, $csv_intFB, $csv_Notes, $csv_Eml1, $csv_Eml2, $csv_Eml3, $csv_Eml4, $csv_PriPhone, $csv_hPhone, $csv_hPhone2, $csv_MPhone, $csv_Pager, $csv_hFax, $csv_hAddress, $csv_hStreet, $csv_hStreet2, $csv_hStreet3, $csv_hPOBox, $csv_hCity, $csv_hState, $csv_hZip, $csv_hCountry, $csv_Spouse, $csv_Children, $csv_ManagersName, $csv_AssistantsName, $csv_RefferedBy, $csv_CompPhone, $csv_BusiPhone, $csv_BusiPhone2, $csv_BusiFax, $csv_AssistantsPhone, $csv_Company, $csv_JobTitle, $csv_Department, $csv_OfficeLocation, $csv_OrgIDNumber, $csv_Profession, $csv_Account, $csv_BusiAddress, $csv_BusiStreet, $csv_BusiStreet2, $csv_BusiStreet3, $csv_BusiPOBox, $csv_BusiCity, $csv_BusiState, $csv_BusiZip, $csv_BusiCountry, $csv_OtherPhone, $csv_OtherFax, $csv_OtherAddress, $csv_OtherStreet, $csv_OtherStreet2, $csv_OtherStreet3, $csv_OtherPOBox, $csv_OtherCity, $csv_OtherZip, $csv_OtherCountry, $csv_Callback, $csv_CarPhone, $csv_RadioPhone, $csv_TTYPhone, $csv_Telex, $csv_User1, $csv_User2, $csv_User3, $csv_User4, $csv_Keywords, $csv_Mialage, $csv_Hobby, $csv_BillingInfo, $csv_DirectoryServer, $csv_Sensitivity, $csv_Private, $csv_Categories Dim $csv_FullName ;this is the column set that i chose for the outlok csv file Dim $csv_FirstLine = "First Name,Middle Name,Last Name,Title,Suffix,Mobile Phone,Initials,Web Page,Gender,Birthday,Anniversary,Location,Language,Internet Free Busy,Notes,E-mail 1 Address,E-mail 2 Address,E-mail 3 Address,E-mail 4 Address,Primary Phone,Home Phone,Home Phone 2,Mobile Phone,Pager,Home Fax,Home Address,Home Street,Home Street 2,Home Street 3,Home Address PO Box,Home City,Home State,Home Postal Code,Home Country,Spouse,Children,Manager's Name,Assistant's Name,Referred By,Company Main Phone,Business Phone,Business Phone 2,Business Fax,Assistant's Phone,Company,Job Title,Department,Office Location,Organizational ID Number,Profession,Account,Business Address,Business Street,Business Street 2,Business Street 3,Business Address PO Box,Business City,Business State,Business Postal Code,Business Country,Other Phone,Other Fax,Other Address,Other Street,Other Street 2,Other Street 3,Other Address PO Box,Other City,Other State,Other Postal Code,Other Country,Callback,Car Phone,ISDN,Radio Phone,TTY/TDD Phone,Telex,User 1,User 2,User 3,User 4,Keywords,Mileage,Hobby,Billing Information,Directory Server,Sensitivity,Priority,Private,Categories" _BlankOut();function to reset vars to "" ;Get vcf file $vcf = FileOpenDialog("Find VCF File", @ScriptDir, "VCF (*.vcf)", 3) If $vcf = "" Then Exit $x = 0 ;open read only $o_vcf = FileOpen($vcf, 0) ;read through file to find start of vcard (if it exists) Do $x += 1 $line = FileReadLine($o_vcf, $x) Until $line = "BEGIN:VCARD" Or @error ;exit if not found If @error Then MsgBox(16, "Error", "Couldn't find VCARD tag. Make sure that you are specifying a valid VCF file and that the file is accessable (readable).") Exit EndIf ;create the outlook object interface $oOutlook = ObjCreate("Outlook.Application") ;create a working direcotry (needs to be accessable to both inital user and user the script is running in DirCreate("C:\temp") DirCreate("C:\temp\OutlookCSV") ;allow choice of save location $csv = FileSaveDialog("CSV File","C:\temp\OutlookCSV","CSV (*.csv)",18,"OutlookCSV_" & @UserName & "." & @MON & "." & @MDAY & "." & @YEAR & ".csv") If $csv = "" Then Exit ;copy the vcf file for backup (still wokring off origional locatoin FileCopy($vcf,"C:\temp\OutlookCSV\PhoneVCF_" & @UserName & "." & @MON & "." & @MDAY & "." & @YEAR & ".vcf",1) ;delete previous csv file (just incase) If FileExists($csv) Then $tmp = FileDelete($csv) If $tmp Then $o_csv = FileOpen($csv, 1) Else MsgBox(16, "Error", "Could not over write previous File. maybe it's open in another program?") Exit EndIf Else $o_csv = FileOpen($csv, 1) EndIf ;write the column set line (first line) FileWriteLine($o_csv, $csv_FirstLine) ;ask user about duplicates $msg = MsgBox(3+32+256,"Ready","I'm ready to start, just one more question. Would you like to import Contacts deemed to be duplicates? (A contact will be deemed duplicate if the FirstName and LastName match exactly).") Switch $msg Case 6 $importDups = True Case 7 $importDups = False Case 2 Exit EndSwitch ;find first vcard If StringInStr(FileReadLine($o_vcf, $x), "BEGIN:VCARD") Then ;make sure its the proper version If StringInStr(FileReadLine($o_vcf, $x + 1), "VERSION:3.0") Then While 1 Do ;loop through till end vcard $x += 1 $line = FileReadLine($o_vcf, $x) ;break each line apart into its individual compnonents $data = StringSplit($line, ";:", 2) ;perfom tasks based on data type ;i will not comment how each tag breaks down, for more info look at http://en.wikipedia.org/wiki/VCard Switch $data[0] Case "N" If UBound($data) >= 3 Then $csv_fn = $data[2] If UBound($data) >= 2 Then $csv_ln = $data[1] If UBound($data) >= 4 Then $csv_mn = $data[3] If UBound($data) >= 5 Then $csv_title = $data[4] Case "ADR" Switch $data[1] Case "TYPE=WORK" If $csv_BusiPOBox <> "" Or $csv_BusiAddress <> "" Or $csv_BusiStreet <> "" Or $csv_BusiCity <> "" Or $csv_BusiState <> "" Or $csv_BusiZip <> "" Or $csv_BusiCountry <> "" Then MsgBox(16, "Error", "Work address already recorded for this contact, sorry I only support 1. script will continue but address will not be moved") Else If UBound($data) = 3 Then $csv_BusiPOBox = $data[2] If UBound($data) = 4 Then $csv_BusiAddress = $data[3] If UBound($data) = 5 Then $csv_BusiStreet = $data[4] If UBound($data) = 6 Then $csv_BusiCity = $data[5] If UBound($data) = 7 Then $csv_BusiState = $data[6] If UBound($data) = 8 Then $csv_BusiZip = $data[7] If UBound($data) = 9 Then $csv_BusiCountry = $data[8] EndIf Case "TYPE=HOME" If $csv_hPOBox <> "" Or $csv_hAddress <> "" Or $csv_hStreet <> "" Or $csv_hCity <> "" Or $csv_hState <> "" Or $csv_hZip <> "" Or $csv_hCountry <> "" Then MsgBox(16, "Error", "Home address already recorded for this contact, sorry I only support 1. script will continue but address will not be moved") Else If UBound($data) = 3 Then $csv_hPOBox = $data[2] If UBound($data) = 4 Then $csv_hAddress = $data[3] If UBound($data) = 5 Then $csv_hStreet = $data[4] If UBound($data) = 6 Then $csv_hCity = $data[5] If UBound($data) = 7 Then $csv_hState = $data[6] If UBound($data) = 8 Then $csv_hZip = $data[7] If UBound($data) = 9 Then $csv_hCountry = $data[8] EndIf EndSwitch Case "BDAY" If UBound($data) > 1 Then $csv_Birth = StringReplace(StringMid($data[1], 5, 2), "0", "") & "/" & StringReplace(StringMid($data[1], 7, 2), "0", "") & "/" & StringMid($data[1], 1, 4) Case "CATEGORIES" If UBound($data) > 1 Then $csv_Categories = $data[1] Case "CLASS" If UBound($data) > 1 Then $csv_Private = $data[1] Case "EMAIL" If $csv_Eml1 <> "" And $csv_Eml2 <> "" And $csv_Eml3 <> "" And $csv_Eml4 <> "" Then MsgBox(16, "Error", "All E-mail slots have been used, no more e-mails will be processed for this contact") Else Switch $data[1] Case "TYPE=PREF" If UBound($data) = 3 Then $csv_Eml1 = $data[2] ElseIf UBound($data) = 4 Then $csv_Eml1 = $data[3] EndIf Case Else If UBound($data) > 1 Then If UBound($data) = 3 Then $tmp = $data[2] ElseIf UBound($data) = 4 Then $tmp = $data[3] ElseIf UBound($data) = 2 Then $tmp = $data[1] EndIf If $csv_Eml2 <> "" Then If $csv_Eml3 <> "" Then $csv_Eml4 = $tmp Else $csv_Eml3 = $tmp EndIf Else $csv_Eml2 = $tmp EndIf EndIf EndSwitch EndIf Case "FN" If UBound($data) = 2 Then $csv_FullName = $data[1] Case "LABEL" If UBound($data) = 2 Then $csv_Notes = $csv_Notes & $data[1] & "\n \n" If UBound($data) = 3 Then $csv_Notes = $csv_Notes & $data[2] & "\n \n" Case "NOTE" If UBound($data) = 2 Then $csv_Notes = $csv_Notes & $data[1] & "\n \n" Case "ORG" If UBound($data) >= 2 Then For $z = 1 To UBound($data) - 1 $csv_Company = $csv_Company & " " & $data[$z] Next EndIf Case "PHOTO" ;can't import into outlook Case "TITLE" If UBound($data) = 2 Then $csv_JobTitle = $data[1] Case "URL" If UBound($data) = 2 Then $csv_Webp = $data[1] Case "TEL" If $csv_Mobile <> "" And $csv_hPhone <> "" And $csv_hPhone2 <> "" And $csv_BusiPhone <> "" And $csv_BusiPhone2 <> "" Then ;All phone numbers have been used for Exces numbers will be put into the Notes Section (May be out of order) $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else Switch $data[1] Case "TYPE=CELL" If $csv_Mobile <> "" Then $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else $csv_Mobile = $data[2] EndIf Case "TYPE=WORK" If $csv_BusiPhone <> "" Then If $csv_BusiPhone2 <> "" Then $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else $csv_BusiPhone2 = $data[2] EndIf Else $csv_BusiPhone = $data[2] EndIf Case "TYPE=HOME" If $csv_hPhone <> "" Then If $csv_hPhone2 <> "" Then $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" Else $csv_hPhone2 = $data[2] EndIf Else $csv_hPhone = $data[2] EndIf Case Else $csv_Notes = $csv_Notes & $data[1] & ": " & $data[2] & "\n \n" EndSwitch EndIf EndSwitch Until $line = "END:VCARD" ;after the end of the card read the next line (checking for a blank line used later) $line = FileReadLine($o_vcf, $x + 1) ;fix the FN field (in case it's blank) will replace it with, in order; last name, full name, email1, email2, blank If $csv_fn = "" Then If $csv_ln = "" Then If $csv_FullName = "" Then If $csv_Eml1 = "" Then If $csv_Eml2 = "" Then ;do nothing Else $csv_fn = $csv_Eml2 EndIf Else $csv_fn = $csv_Eml1 EndIf Else $csv_fn = $csv_FullName EndIf Else $csv_fn = $csv_ln EndIf EndIf ;write the line to the csv file FileWriteLine($o_csv, $csv_fn & "," & $csv_mn & "," & $csv_ln & "," & $csv_title & "," & $csv_suf & "," & $csv_Mobile & "," & $csv_initials & "," & $csv_Webp & "," & $csv_Gen & "," & $csv_Birth & "," & $csv_Ann & "," & $csv_loc & "," & $csv_lang & "," & $csv_intFB & "," & $csv_Notes & "," & $csv_Eml1 & "," & $csv_Eml2 & "," & $csv_Eml3 & "," & $csv_Eml4 & "," & $csv_PriPhone & "," & $csv_hPhone & "," & $csv_hPhone2 & "," & $csv_MPhone & "," & $csv_Pager & "," & $csv_hFax & "," & $csv_hAddress & "," & $csv_hStreet & "," & $csv_hStreet2 & "," & $csv_hStreet3 & "," & $csv_hPOBox & "," & $csv_hCity & "," & $csv_hState & "," & $csv_hZip & "," & $csv_hCountry & "," & $csv_Spouse & "," & $csv_Children & "," & $csv_ManagersName & "," & $csv_AssistantsName & "," & $csv_RefferedBy & "," & $csv_CompPhone & "," & $csv_BusiPhone & "," & $csv_BusiPhone2 & "," & $csv_BusiFax & "," & $csv_AssistantsPhone & "," & $csv_Company & "," & $csv_JobTitle & "," & $csv_Department & "," & $csv_OfficeLocation & "," & $csv_OrgIDNumber & "," & $csv_Profession & "," & $csv_Account & "," & $csv_BusiAddress & "," & $csv_BusiStreet & "," & $csv_BusiStreet2 & "," & $csv_BusiStreet3 & "," & $csv_BusiPOBox & "," & $csv_BusiCity & "," & $csv_BusiState & "," & $csv_BusiZip & "," & $csv_BusiCountry & "," & $csv_OtherPhone & "," & $csv_OtherFax & "," & $csv_OtherAddress & "," & $csv_OtherStreet & "," & $csv_OtherStreet2 & "," & $csv_OtherStreet3 & "," & $csv_OtherPOBox & "," & $csv_OtherCity & "," & $csv_OtherZip & "," & $csv_OtherCountry & "," & $csv_Callback & "," & $csv_CarPhone & "," & $csv_RadioPhone & "," & $csv_TTYPhone & "," & $csv_Telex & "," & $csv_User1 & "," & $csv_User2 & "," & $csv_User3 & "," & $csv_User4 & "," & $csv_Keywords & "," & $csv_Mialage & "," & $csv_Hobby & "," & $csv_BillingInfo & "," & $csv_DirectoryServer & "," & $csv_Sensitivity & "," & $csv_Private & "," & $csv_Categories) ;see if user wanted duplicates If $importDups Then $doIt = True Else ;check for duplicates $doIt = SearchContact($csv_fn,$csv_ln,$oOutlook) EndIf ;if importdups or contact doesn't exist then add it If $doIt Then ;create a contact item (thats what the 2 means) there are different enums for different objects $contactitem = $oOutlook.CreateItem(2) ;build contact item $contactitem.FirstName = $csv_fn $contactitem.MiddleName = $csv_mn $contactitem.LastName = $csv_ln $contactitem.Title = $csv_title $contactitem.Suffix = $csv_suf $contactitem.MobileTelephoneNumber = $csv_Mobile $contactitem.Initials = $csv_initials $contactitem.PersonalHomePage = $csv_Webp ;~ $contactitem.Gender = "" If Not $csv_Birth = "0/0/00" Then $contactitem.Birthday = $csv_Birth If Not $csv_Ann = "0/0/00" Then $contactitem.Anniversary = $csv_Ann $contactitem.OfficeLocation = $csv_loc $contactitem.Language = $csv_lang $contactitem.InternetFreeBusyAddress = $csv_intFB $contactitem.Body = $csv_Notes $contactitem.Email1Address = $csv_Eml1 $contactitem.Email2Address = $csv_Eml2 $contactitem.Email3Address = $csv_Eml3 ;~ $contactitem.= $csv_Eml4 $contactitem.PrimaryTelephoneNumber = $csv_PriPhone $contactitem.HomeTelephoneNumber = $csv_hPhone $contactitem.Home2TelephoneNumber = $csv_hPhone2 $contactitem.MobileTelephoneNumber = $csv_MPhone $contactitem.PagerNumber = $csv_Pager $contactitem.HomeFaxNumber = $csv_hFax $contactitem.HomeAddress = $csv_hAddress $contactitem.HomeAddressStreet = $csv_hStreet ;~ $contactitem.= $csv_hStreet2 ;~ $contactitem.= $csv_hStreet3 $contactitem.HomeAddressPostOfficeBox = $csv_hPOBox $contactitem.HomeAddressCity = $csv_hCity $contactitem.HomeAddressState = $csv_hState $contactitem.HomeAddressPostalCode = $csv_hZip $contactitem.HomeAddressCountry = $csv_hCountry $contactitem.Spouse = $csv_Spouse $contactitem.Children = $csv_Children $contactitem.ManagerName = $csv_ManagersName $contactitem.AssistantName = $csv_AssistantsName ;~ $contactitem.= $csv_RefferedBy $contactitem.CompanyMainTelephoneNumber = $csv_CompPhone $contactitem.BusinessTelephoneNumber = $csv_BusiPhone $contactitem.Business2TelephoneNumber = $csv_BusiPhone2 $contactitem.BusinessFaxNumber = $csv_BusiFax $contactitem.AssistantTelephoneNumber = $csv_AssistantsPhone $contactitem.Companies = $csv_Company $contactitem.JobTitle = $csv_JobTitle $contactitem.Department = $csv_Department $contactitem.OfficeLocation = $csv_OfficeLocation $contactitem.OrganizationalIDNumber = $csv_OrgIDNumber $contactitem.Profession = $csv_Profession $contactitem.Account = $csv_Account $contactitem.BusinessAddress = $csv_BusiAddress $contactitem.BusinessAddressStreet = $csv_BusiStreet ;~ $contactitem.= $csv_BusiStreet2 ;~ $contactitem.= $csv_BusiStreet3 $contactitem.BusinessAddressPostOfficeBox = $csv_BusiPOBox $contactitem.BusinessAddressCity = $csv_BusiCity $contactitem.BusinessAddressState = $csv_BusiState $contactitem.BusinessAddressPostalCode = $csv_BusiZip $contactitem.BusinessAddressCountry = $csv_BusiCountry $contactitem.OtherTelephoneNumber = $csv_OtherPhone $contactitem.OtherFaxNumber = $csv_OtherFax $contactitem.OtherAddress = $csv_OtherAddress $contactitem.OtherAddressStreet = $csv_OtherStreet ;~ $contactitem.= $csv_OtherStreet2 ;~ $contactitem.= $csv_OtherStreet3 $contactitem.OtherAddressPostOfficeBox = $csv_OtherPOBox $contactitem.OtherAddressCity = $csv_OtherCity $contactitem.OtherAddressPostalCode = $csv_OtherZip $contactitem.OtherAddressCountry = $csv_OtherCountry $contactitem.CallbackTelephoneNumber = $csv_Callback $contactitem.CarTelephoneNumber = $csv_CarPhone $contactitem.RadioTelephoneNumber = $csv_RadioPhone $contactitem.TTYTDDTelephoneNumber = $csv_TTYPhone $contactitem.TelexNumber = $csv_Telex $contactitem.User1 = $csv_User1 $contactitem.User2 = $csv_User2 $contactitem.User3 = $csv_User3 $contactitem.User4 = $csv_User4 ;~ $contactitem.= $csv_Keywords $contactitem.Mileage = $csv_Mialage $contactitem.Hobby = $csv_Hobby $contactitem.BillingInformation = $csv_BillingInfo $contactitem.NetMeetingServer = $csv_DirectoryServer ;~ $contactitem. = $csv_Sensitivity ;~ $contactitem.= $csv_Private ;~ $contactitem.= $csv_Categories ;save the contact item $contactitem.Close(0) EndIf ;reset the variables _BlankOut() ;this is where that blank line check comes into play If $line = "" Then ExitLoop WEnd ;close files FileClose($o_csv) FileClose($o_vcf) ;copy CSV to inbox $oOutlook.CopyFile($csv, "Inbox") ;success MsgBox(64,"Done!","If you are seeing this message the utility has completed with no errors. Check to see that the contacts are imported properly.") Else ;incorrect version message MsgBox(16, "Correct but no", "What you have here is a Vcard of the incorrect version, sorry.. at this time I'm only supporting 3.0") Exit EndIf Else ;incorrect vcard file MsgBox(16, "Error", "This does not appear to be a correct vcard file") Exit EndIf EndIf Func SearchContact($inFirst, $inLast, ByRef $oOutlook) ;declare variables Dim $Cible Dim $dossierContacts ;create filter $sFilter = "[FirstName] = " & Chr(34) & $inFirst & Chr(34) ;attatch to namespace $namespace = $oOutlook.GetNamespace("MAPI") ;get contacts folder (10) $dossierContacts = $namespace.GetDefaultFolder(10) ;perform a search of the contacts $Cible = $dossierContacts.Items.Find($sFilter) ;if first name is found check last name If IsObj($Cible) Then If $Cible.LastName = $inLast Then ;contact would be a duplicate (False means don't do it) Return False Else ;firstname match lastname didn't, not a duplicate Return True EndIf Else ;no match Return True EndIf EndFunc ;==>SearchContact Func _BlankOut() ;sets all vars to a default or blank value $csv_fn = "" $csv_mn = "" $csv_ln = "" $csv_title = "" $csv_suf = "" $csv_Mobile = "" $csv_initials = "" $csv_Webp = "" $csv_Gen = "" $csv_Birth = "0/0/00" $csv_Ann = "0/0/00" $csv_loc = "" $csv_lang = "" $csv_intFB = "" $csv_Notes = "" $csv_Eml1 = "" $csv_Eml2 = "" $csv_Eml3 = "" $csv_Eml4 = "" $csv_PriPhone = "" $csv_hPhone = "" $csv_hPhone2 = "" $csv_MPhone = "" $csv_Pager = "" $csv_hFax = "" $csv_hAddress = "" $csv_hStreet = "" $csv_hStreet2 = "" $csv_hStreet3 = "" $csv_hPOBox = "" $csv_hCity = "" $csv_hState = "" $csv_hZip = "" $csv_hCountry = "" $csv_Spouse = "" $csv_Children = "" $csv_ManagersName = "" $csv_AssistantsName = "" $csv_RefferedBy = "" $csv_CompPhone = "" $csv_BusiPhone = "" $csv_BusiPhone2 = "" $csv_BusiFax = "" $csv_AssistantsPhone = "" $csv_Company = "" $csv_JobTitle = "" $csv_Department = "" $csv_OfficeLocation = "" $csv_OrgIDNumber = "" $csv_Profession = "" $csv_Account = "" $csv_BusiAddress = "" $csv_BusiStreet = "" $csv_BusiStreet2 = "" $csv_BusiStreet3 = "" $csv_BusiPOBox = "" $csv_BusiCity = "" $csv_BusiState = "" $csv_BusiZip = "" $csv_BusiCountry = "" $csv_OtherPhone = "" $csv_OtherFax = "" $csv_OtherAddress = "" $csv_OtherStreet = "" $csv_OtherStreet2 = "" $csv_OtherStreet3 = "" $csv_OtherPOBox = "" $csv_OtherCity = "" $csv_OtherZip = "" $csv_OtherCountry = "" $csv_Callback = "" $csv_CarPhone = "" $csv_RadioPhone = "" $csv_TTYPhone = "" $csv_Telex = "" $csv_User1 = "" $csv_User2 = "" $csv_User3 = "" $csv_User4 = "" $csv_Keywords = "" $csv_Mialage = "" $csv_Hobby = "" $csv_BillingInfo = "" $csv_DirectoryServer = "" $csv_Sensitivity = "" $csv_Private = "" $csv_Categories = "" EndFunc ;==>_BlankOut Link to comment Share on other sites More sharing options...
water Posted April 5, 2013 Share Posted April 5, 2013 When you use Google you will find a lot of hits like this one to import VCF files. This VB example should be easy to convert to AutoIt:Sub OpenSaveVCard() Dim objWSHShell As Object Dim objOL As Outlook.Application Dim colInsp As Outlook.Inspectors Dim strVCName As String Dim vCounter As Integer Dim ff As String ff = Dir("d:\contacts\*.vcf") Do While Len(ff) strVCName = "d:\contacts\" & ff Set objOL = CreateObject("Outlook.Application") Set colInsp = objOL.Inspectors If colInsp.Count = 0 Then Set objWSHShell = CreateObject("WScript.Shell") objWSHShell.Run Chr(34) & strVCName & Chr(34) Set colInsp = objOL.Inspectors If Err = 0 Then Do Until colInsp.Count = 1 DoEvents Loop colInsp.Item(1).CurrentItem.Save colInsp.Item(1).Close olDiscard Set colInsp = Nothing Set objOL = Nothing Set objWSHShell = Nothing End If End If ff = Dir Loop End Sub My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
tlman12 Posted April 8, 2013 Author Share Posted April 8, 2013 When you use Google you will find a lot of hits like this one to import VCF files. This VB example should be easy to convert to AutoIt:yes, i did goole, and i did find that exact script, but it only works on single contact vcards version 2.1. if you have a multi contact vcard version 3.0 you will only get the first vcard in the file. my example above imports all contacts withing a version 3.0 vcard file. Link to comment Share on other sites More sharing options...
water Posted April 8, 2013 Share Posted April 8, 2013 I see. Thank you very much for sharing! My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now