Solved

As an error with the required object in VBA

Posted on 2011-03-22
2
432 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:Thomas_Meyer
2 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 35192834
Change:

   file = sTemp & "\" & student_scores.Log

to:

   file = sTemp & "\student_scores.Log"

Kevin
0
 

Author Closing Comment

by:Thomas_Meyer
ID: 35193044
helped, thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question