Private Sub CommandButton1_Click()
Dim fso As Object
Dim path As String
Dim ofolder As Object
Dim osubfolder As Object
Dim ofile As Object
Dim wrd As Object
Dim docs As Object
Set fso = CreateObject("Scripting.filesystemobject")
path = "C:\users\me\Desktop\here"
If Right(path, 1) <> Application.PathSeparator Then
path = path & Application.PathSeparator
End If
Set ofolder = fso.GetFolder(path)
For Each osubfolder In ofolder.subfolders
MsgBox (osubfolder.Name) 'correct subfolder
For Each ofile In osubfolder.Files
If LCase(fso.GetExtensionName(ofile.path)) Like "doc*" Then
MsgBox (ofile.Name) 'correct file name
Set wrd = CreateObject("word.application")
wrd.Visible = True 'opens Word
Set docs = wrd.Documents
docs.Open (ofile.path)
Exit Sub 'for testing
End If
Next ofile
Next osubfolder
Set wrd = Nothing
Set fso = Nothing
End Sub
Artik