Hi Greg,
The following code will do that, saving the log file in the folder that
contained the documents that were processed:
Option Explicit
Dim myFile As String
Dim Files As Variant
Dim FileList As String
Dim i As Long, j As Long
Private Sub cmdCancel_Click()
'If Documents.Count > 0 Then
' Documents.Close Savechanges:=wdPromptToSaveChanges
'End If
Unload Me
End Sub
Private Sub cmdGo_Click()
Dim myDoc As Document
Dim Log As Document
Dim Logstr As String
Logstr = ""
myFile = Dir$(PathToUse & "*.doc")
FileList = ""
Do While myFile <> ""
FileList = FileList & myFile & "#"
myFile = Dir$()
Loop
FileList = Left(FileList, Len(FileList) - 1)
Files = Split(FileList, "#")
j = UBound(Files) + 1
Application.ScreenUpdating = False
For i = 0 To j - 1
Set myDoc = Documents.Open(PathToUse & Files(i))
Me.lblNowProcessing.Visible = True
Me.lblNowProcessing.Caption = "Now processing " & Files(i)
Me.Repaint
'Call procedure to containing the processing code
ProcessDocument myDoc
With myDoc
.Saved = False
.Save
.Close
End With
Logstr = Logstr & Files(i) & " processed at " & Now & vbCr
Next i
i = i + 1
Application.ScreenUpdating = True
Me.lblFolder.Caption = "Completed processing files in " & PathToUse & "."
Me.lblNowProcessing.Visible = False
Me.cmdGo.Visible = False
Me.cmdCancel.Caption = "Exit"
Set Log = Documents.Add
Log.Range = "The following documents were processed from the folder " &
PathToUse & " at the times indicated:" & vbCr & Logstr
Log.SaveAs PathToUse & "Log.doc"
End Sub
Private Sub UserForm_Initialize()
Me.lblNowProcessing.Visible = False
End Sub
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP