Try:
Code:
Sub RenameDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strFlNm As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
If .Tables.Count > 0 Then
With .Tables(1)
If .Rows.Count > 6 And .Columns.Count > 2 Then
strFlNm = Split(.Cell(7, 3).Range.Text, vbCr)(0) & " " & _
Split(.Cell(5, 1).Range.Text, vbCr)(0) & " " & _
Split(.Cell(2, 1).Range.Text, vbCr)(0)
End If
End With
End If
.Close SaveChanges:=False
End With
If Trim(strFlNm) <> "" Then Name strFolder & "\" & strFile As strFolder & "\" & strFlNm & ".docx"
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
The code includes a folder browser, so all you need do is select the folder to process and all eligible files in that folder will be renamed.