Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nagolpj

macrumors newbie
Original poster
Sep 11, 2009
1
0
I get these tables of zip code data in Word (.doc) format and they need to be parsed and formatted into CSV to import on a web site. I just need the 5 digit zip codes. I used to have a macro that could do it but my department switched from PC's to Mac's and now I'm lost. Can Applescript do something like what I need?

Here is the code I used for my old macro.

Code:
Sub zipCodeList()
    Dim DocResult As Document, Ctr As Long
    Dim DocSource As Document, myFile As String
    Application.ScreenUpdating = False
    Set DocResult = Application.Documents.Add
    With Application.Dialogs(wdDialogFileOpen)
        .Name = "*.doc*"
        .Show
    End With
    myFile = ActiveDocument.Name
    Set DocSource = ActiveDocument
    myFile = ActiveDocument.Name
    Do While Ctr < ActiveDocument.Paragraphs.Count
        Selection.Expand wdParagraph
        For i = 1 To Len(Selection.Text) - 5
            var2 = Mid(Selection.Text, i, 5)
            If IsNumeric(Mid(Selection.Text, i, 5)) And _
            InStr(1, Mid(Selection.Text, i, 5), " ") = 0 Then
                If InStr(1, Mid(Selection.Text, i, 5), Chr(9)) = 0 Then
                    var1 = Selection.Text
                    txt = Mid(Selection.Text, i, 5)
                    DocResult.Activate
                    Selection.InsertAfter txt
                    Selection.InsertAfter vbCrLf
                    Selection.Move wdParagraph, 1
                    DocSource.Activate
                    i = i + 5
                End If
            End If
        Next i
        Selection.Move wdParagraph, 1
        Ctr = Ctr + 1
     Loop
    Documents(myFile).Close
    Application.ScreenUpdating = True
End Sub
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.