Sub listDocs()
Dim FileSystem As Object
Dim HostFolder As String
'change folder name as needed
HostFolder = "C:\users\myname"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
getDocs FileSystem.GetFolder(HostFolder)
End Sub
Sub getDocs(Folder)
Dim SubFolder As Object
For Each SubFolder In Folder.SubFolders
Debug.Print SubFolder
getDocs SubFolder
Next
Dim File
For Each File In Folder.Files
If File.Type = "Microsoft Word Document" Then
Documents.Open FileName:=File.Path, ReadOnly:=True
Debug.Print File.Path, Documents(File.Name).AttachedTemplate
Documents(File.Name).Close
End If
Next
End Sub
这对我有用:
这是基于https://stackoverflow.com/questions/22645347/loop-through-all-subfolders-using-vba。它将打印每个文件夹和每个 Word 文件及其模板名称。
请注意,这将需要很长时间,因为它需要打开您身上的每个 Word 文件