NextContact:
Next varItem
If Nz(InStr(strWordTemplate, “List”)) > 0 Then
Delete redundant last (blank) row:
With appWord.Selection
.SelectRow
.Rows.Delete
.HomeKey unit:=wdStory
End With
End If
Check for the previously saved document in the documents folder, and append an incremented
number to the save name if one is found:
strDocType = _
appWord.ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle)
strSaveName = strDocType & “ on “ _
& strShortDate & strExtension
i = 2
intSaveNameFail = True
Do While intSaveNameFail
strSaveNamePath = strDocsPath & strSaveName
Debug.Print “Proposed save name and path: “ _
& vbCrLf & strSaveNamePath
strTestFile = Nz(Dir(strSaveNamePath))
Debug.Print “Test file: “ & strTestFile
If strTestFile = strSaveName Then
Debug.Print “Save name already used: “ _
& strSaveName
Create a new save name with the incremented number:
intSaveNameFail = True
strSaveName = strDocType & “ “ & CStr(i) & “ on “ _
& strShortDate & strExtension
strSaveNamePath = strDocsPath & strSaveName
Debug.Print “New save name and path: “ _
& vbCrLf & strSaveNamePath
i = i + 1
Else
Debug.Print “Save name not used: “ & strSaveName
intSaveNameFail = False
End If
Loop
Part II Writing VBA Code to Exchange Data between Office Components