Import contact info from Mac Address Book 4.0.6

the magician

Active Member
Joined
Nov 9, 2006
Messages
496
At job, Mac OSX and Address Book 4.0.6 with contact info including in many cases emails. I'd like to get it of there, into Excel to manipulate, and ultimately into a FileWrecker Pro database. How to export 1087 entries from Address Book including only selective data fields is the question, and I know that's "slightly" OT, but I do want to import into Excel, so I hope that vindicates me! :) If not, and you can point me to a good MacForum, I'll settle.

Thanks.

el mago

"poof"
 
I used Automator to create a workflow ("automate.workflow") that saved the AddressBook as vcf.
then this calls that workflow and returns the filepath as a / delimited string.
Code:
Sub test()
Dim scriptText As String
scriptText = "tell application ""Finder"" " & vbCr
scriptText = scriptText & "Activate" & vbCr
scriptText = scriptText & "    open document file ""automate.workflow"" of folder ""Desktop"" of folder ""merickson"" of folder ""Users"" of startup disk" & vbCr
scriptText = scriptText & "end tell" & vbCr
scriptText = scriptText & "tell application ""Automator"" " & vbCr
scriptText = scriptText & "execute workflow ""automate.workflow""" & vbCr
scriptText = scriptText & "end tell"
'MsgBox scriptText
MsgBox MacScript(scriptText)
End Sub
I'm not experienced with automation, but I think I need to add a tell to the script to give the focus back to Excel. (I might be able to have Excel write the Automater workflow as well as the AppleScript script.) Once this gives us the file path to the .vcf, the reorganizing and parsing is scut.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I added this to your original code:

If .Cells(rNum, 1) Like "EMAIL;type=INTERNET;type=WORK*" Then
resultRRay(2, outPoint) = .Cells(rNum, 2).Value
End If
' If .Cells(rNum, 1) Like "EMAIL;type=INTERNET;type=HOME*" Then
' resultRRay(3, outPoint) = .Cells(rNum, 3).Value
' End If

As it is, it works just like original did. So, what changes need to be made to include a third element of the array (by un-commenting the HOME if-endif) to allow for "HOME" email to be included?
 
Upvote 0
What about the section below? It seems I need a .Columns(3).FormulaR1C1 to capture the secondary emails?

With .Offset(0, 2)
.Columns(1).FormulaR1C1 = "=SUBSTITUTE(SUBSTITUTE(RC[-2],"";"","", "",1),"";"","""")"
.Columns(2).FormulaR1C1 = "=RC[-2]"
.Value = .Value
End With
 
Upvote 0
Magician

You've post just 2 bits of data albeit different , how do you expect us to write/suggest code for all the possibilities?

Is your data, it's an application eg MacAddressBook that I don't think is used by many people on this site.

One think I was going to suggest was to do a select all and copy, don't know that would work if if it's even possible.:)

PS All of the above comes with the caveat that I'm watching that Who film.:eek:
 
Upvote 0
I got involved in trying to get Excel to automate the Export.
Before I got to that, I put this together for the import and converting it into Excel Standard format (header row etc.) The sub that cleans the entries still needs to be done.
Code:
Option Explicit
Dim newWorkbook As Workbook

Sub MainRoutine()
Call ImportFromAddressBook
Call RearrangeData
End Sub

Sub RearrangeData()

'Set newWorkbook = Application.Workbooks("aTest.vcf")
Dim fileList As Variant, Headers As Variant
Dim outRRay As Variant
Dim lookRow As Long, putRow As Long, putCol As Long
Dim testVal As String, putVal As String
fileList = Array("N", "EMAIL*WORK*", "EMAIL*HOME*", "TEL*WORK*", "TEL*CELL*", "TEL*HOME*", "*URL*", "CATEGORIES*", "*.ADR*")
Headers = Array("Name", "WorkE-mail", "HomeE-Mail", "WorkPhone", "CellPhone", "HomePhone", "URL", "Category", "Address")
With newWorkbook.Sheets(1).Range("A:A")
    With Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
        .TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :=":", FieldInfo:=Array(Array(1, 1), Array(2, 1))
    End With
    With Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
        With .Offset(0, 3)
            .FormulaR1C1 = "=RC[-2]&IF(LEN(RC[-1])=0,"""","":""&RC[-1])"
            .Value = .Value
        End With
        .Offset(0, 1).Resize(, 2).Delete shift:=xlToLeft
 
        ReDim outRRay(1 To UBound(Headers) + 1, 1 To .Rows.Count)
        For lookRow = 1 To .Rows.Count
            testVal = .Cells(lookRow, 1).Value
            putVal = .Cells(lookRow, 2).Value
            If testVal = "BEGIN" Then
                putRow = putRow + 1
            Else
                For putCol = 0 To UBound(fileList)
                    If testVal Like fileList(putCol) Then
                        outRRay(putCol + 1, putRow) = putVal
                        Exit For
                    End If
                Next putCol
            End If
        Next lookRow
    
    ReDim Preserve outRRay(1 To UBound(outRRay, 1), 1 To putRow)
        With .Parent.Range("C1")
            .Resize(1, UBound(Headers) + 1).Value = Headers
            .Offset(1, 0).Resize(UBound(outRRay, 2), UBound(outRRay, 1)).Value = Application.Transpose(outRRay)
        End With
    .Resize(, 2).EntireColumn.Delete
    End With
End With

End Sub

Sub ImportFromAddressBook()
    Dim pathStr As String
    Dim resultRRay As Variant
    Dim rNum As Long, outPoint As Long
    pathStr = Application.GetOpenFilename
    If Not (pathStr = "False") Then
        On Error GoTo HaltRoutine
        Set newWorkbook = Workbooks.Open(pathStr)
    End If
    On Error GoTo 0
    Exit Sub
HaltRoutine:
    On Error GoTo 0
    MsgBox "File Error"
    End
End Sub
Norie: No, Macs Address Book is not suitable for copy pasting to Excel. I don't believe that you can view more than one record at a time. It's not one of the best efforts from Cuppertio. I hope that the Magician is doing this in prepertion to abandoning that software and switching his data to Excel.
 
Last edited:
Upvote 0
Norie - thanks for staying tuned, must be during commercials. Actually Mike has coded it to work, but so far I'm only getting name and primary email. I'm tweaking now to see if I can get a secondary email, and it's almost there.

Mike - we're still not quite there yet. Fine up to this point, and I think I still need another "3" or two in here, maybe in the offsets, or resize?

Code:
            With .Offset(0, 2).Resize(outPoint, 2)
                .Value = Application.Transpose(resultRRay)
                With .Offset(0, 2)
                    .Columns(1).FormulaR1C1 = "=SUBSTITUTE(SUBSTITUTE(RC[-2],"";"","", "",1),"";"","""")"
                    .Columns(2).FormulaR1C1 = "=RC[-2]"
                    .Columns(3).FormulaR1C1 = "=RC[-3]"
                   .Value = .Value
                End With
                Range(.Parent.Range("a1"), .Cells).EntireColumn.Delete
            End With
 
Upvote 0
Getting error 13 type mismatch on
Code:
            .Offset(1, 0).Resize(UBound(outRRay, 2), UBound(outRRay, 1)).Value = Application.Transpose(outRRay)
 
Upvote 0

Forum statistics

Threads
1,222,554
Messages
6,166,761
Members
452,069
Latest member
myanis72

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top