You have missed a
myFile = Dir$()
command inside the While>Wend loop.
Use
Sub batchFormating()
Dim myFile As String
Dim myDoc As Document
Dim path As String
Dim fDlg As FileDialog
On Error Resume Next
Set fDlg = Application.FileDialog(msoFileDialogFolderPicker)
With fDlg
.Title = "Select folder and type OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Canceled", , "Batch formating"
Exit Sub
End If
path = fDlg.SelectedItems.Item(1)
If Right(path, 1) <> "\" Then path = path + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
FirstLoop = True
myFile = Dir$(path & "*.doc")
While myFile <> ""
Set myDoc = Documents.Open(path & myFile)
With myDoc
.Range.Font.Italic = True
.Close SaveChanges:=wdSaveChanges
End With
myFile = Dir$() 'This line was missing
Wend
Set fDlg = Nothing
Set myDoc = Nothing
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, originally posted via msnews.microsoft.com
Hello. Thank you very much.
OK, I use next code (+ your tips) for all docs into one folder. But I
get the cycling. How to do correct this code? Thank you.
Sub batchFormating()
Dim myFile As String
Dim myDoc As Document
Dim path As String
Dim fDlg As FileDialog
On Error Resume Next
Set fDlg = Application.FileDialog(msoFileDialogFolderPicker)
With fDlg
.Title = "Select folder and type OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Canceled", , "Batch formating"
Exit Sub
End If
path = fDlg.SelectedItems.Item(1)
If Right(path, 1) <> "\" Then path = path + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
FirstLoop = True
myFile = Dir$(path & "*.doc")
While myFile <> ""
Set myDoc = Documents.Open(path & myFile)
With myDoc
.Range.Font.Italic = True
.Close SaveChanges:=wdSaveChanges
End With
Wend
Set fDlg = Nothing
Set myDoc = Nothing
End Sub