Andre205th
03-21-2020, 12:32 PM
My problem is, when I try to open the Word files I get a Runtime Error 424: Object Required.
Any ideas?
Private Sub CommandButton1_Click()
Dim fso As Object
Set fso = CreateObject("Scripting.filesystemobject")
Dim path As String
path = "C:\users\me\Desktop\here"
Dim ofolder As Object
Set ofolder = fso.GetFolder(path)
Dim osubfolders As Object
Set osubfolders = ofolder.subfolders
For Each osubfolders In ofolder.subfolders
Dim ofiles As Object
MsgBox (osubfolders.Name) 'correct subfolder
For Each ofiles In osubfolders.Files
MsgBox (ofiles.Name) 'correct file name
Dim wrd As Object
Set wrd = CreateObject("word.application")
wrd.Visible = True 'opens Word
Dim doc As Object
Set doc = wrd.Documents
doc.Open (path & "" & osubfolder.Name & "" & ofiles.Name) '******Runtime Error 424: Object Requirement
Exit Sub 'for testing
Next ofiles
Next osubfolders
End Sub
</code>
Any ideas?
Private Sub CommandButton1_Click()
Dim fso As Object
Set fso = CreateObject("Scripting.filesystemobject")
Dim path As String
path = "C:\users\me\Desktop\here"
Dim ofolder As Object
Set ofolder = fso.GetFolder(path)
Dim osubfolders As Object
Set osubfolders = ofolder.subfolders
For Each osubfolders In ofolder.subfolders
Dim ofiles As Object
MsgBox (osubfolders.Name) 'correct subfolder
For Each ofiles In osubfolders.Files
MsgBox (ofiles.Name) 'correct file name
Dim wrd As Object
Set wrd = CreateObject("word.application")
wrd.Visible = True 'opens Word
Dim doc As Object
Set doc = wrd.Documents
doc.Open (path & "" & osubfolder.Name & "" & ofiles.Name) '******Runtime Error 424: Object Requirement
Exit Sub 'for testing
Next ofiles
Next osubfolders
End Sub
</code>