
Automated file name processing...
Jerry,
I am using an Access database to hold information about
constituant Word documents. The code that I posted is
only a small portion of the routine I am using.
I create an ADODB.Recordset object and read through an
Access query that contains the "names" of all of the
documents that I wish to compile in to a single file.
Here is a quick summary of what I am doing:
sSQL = "SELECT * from qryCheckList"
Set pRS = New ADODB.Recordset
pRS.CursorLocation = adUseServer
conMDB.Errors.Clear
pRS.Open sSQL, conMDB, adOpenStatic, adLockReadOnly
If (pRS.BOF) And (pRS.EOF) Then
MsgBox "No documents available!", _
vbOKOnly + vbExclamation, _
"Nothing to process. Exiting."
Exit Sub
Else
If objWord Is Nothing Then
Set objWord = New Word.Application
Else
Set objWord = GetObject(, "Word.Application")
End If
objWord.Documents.Add
Set pWordDoc = objWord.ActiveDocument
pRS.MoveFirst
While (Not pRS.EOF)
sSourceFileName = pRS.Fields("SOURCEFILENAME").Value
If (sys_IsFileExists(sSourceFileName) = True) Then
pWordDoc.Parent.Selection.EndKey 6
pWordDoc.Parent.Selection.InsertFile sSourceFileName
end if 'make sure file exists!!!
pWordDoc.Parent.Selection.EndKey 6
pRS.MoveNext
Wend
End If 'recordset exists?
pRS.Close
Set pRS = Nothing
pWordDoc.SaveAs (sWorkingDocName)
pWordDoc.Close
Set pWordDoc = Nothing
Set objWord = Nothing
HTH