As an error with the required object in VBA

Hi,
can you help me with my macro to delete a file? When I start writing on the fifth row of the error: Run-time error '424' - Object required
Thank you in advance.

Regards,
TM
Sub DeleteFile()
Dim fso, sTemp
Dim file As String
sTemp = Environ("TEMP")
file = sTemp & "\" & student_scores.Log
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
    fso.DeleteFile file, True
Else
    MsgBox file & " does not exist or has already been deleted!" _
            , vbExclamation, "File not Found"
End If
End Sub

Open in new window

Thomas_MeyerAsked:
Who is Participating?
 
zorvek (Kevin Jones)Connect With a Mentor ConsultantCommented:
Change:

   file = sTemp & "\" & student_scores.Log

to:

   file = sTemp & "\student_scores.Log"

Kevin
0
 
Thomas_MeyerAuthor Commented:
helped, thanks!
0
All Courses

From novice to tech pro — start learning today.