'Primer 14: Kolekcije i osnovni objekti u Word-u (Application, Documents, ActiveDocument, Selection)
Sub pozivnice()
    Dim zvanice As New Collection
    zvanice.Add "Jessica Alba"
    zvanice.Add "Eva Mendes"
    zvanice.Add "Angelina Jolie"
    zvanice.Add "Pamela Anderson"
    
    Dim sDir As String
    sDir = "C:\g3\prog\"
    If Not FileOrDirExists(sDir) Then
        MsgBox "Katalog koji ste zadali kao mesto za cuvanje pozivnica ne postoji! Odustajemo..."
        Exit Sub
    End If
    
    Dim zvanica As Variant 'For Each naredba zahteva ili promenljivu tipa Variant ili promenljivu tipa Object
    For Each zvanica In zvanice
        Application.Documents.Add
        'CStr vrsi konverziju tipa promenljive zvanica iz Variant u String; u protivnom funkcija odrediIme javlja gresku
        Selection.TypeText "Dear " & odrediIme(CStr(zvanica)) & "," 
        Selection.TypeParagraph
        Selection.TypeParagraph
        Selection.TypeText "It will be an honor to have you as a guest on our party."
        Selection.TypeText " The show begins at 20:00. Don't be late."
        Selection.TypeParagraph
        Selection.TypeText "Feel free to bring a (lady-)friend."
        Selection.TypeText " We have enough boys over here."
        Selection.TypeParagraph
        Selection.TypeParagraph
        Selection.TypeText "Sincerely,"
        Selection.TypeParagraph
        Selection.TypeText "your true admirer"
        ActiveDocument.SaveAs (sDir & zvanica & ".doc")
        ActiveDocument.Close
    Next
End Sub

Function odrediIme(punoIme As String) As String
    Dim niz() As String
    niz = Split(punoIme, " ")
    odrediIme = niz(0)
    
End Function

Function odrediPrezime() As String
    Dim niz() As String
    niz = Split(punoIme, " ")
    odrediIme = niz(1)
End Function

Function FileOrDirExists(PathName As String) As Boolean
     'Macro Purpose: Function returns TRUE if the specified file
     '               or folder exists, false if not.
     'PathName     : Supports Windows mapped drives or UNC
     '             : Supports Macintosh paths
     'File usage   : Provide full file path and extension
     'Folder usage : Provide full folder path
     '               Accepts with/without trailing "\" (Windows)
     '               Accepts with/without trailing ":" (Macintosh)
     
    Dim iTemp As Integer
     
     'Ignore errors to allow for error evaluation
    On Error Resume Next
    iTemp = GetAttr(PathName)
     
     'Check if error exists and set response appropriately
    Select Case Err.Number
    Case Is = 0
        FileOrDirExists = True
    Case Else
        FileOrDirExists = False
    End Select
     
     'Resume error checking
    On Error GoTo 0
End Function