Skip to content

Instantly share code, notes, and snippets.

@Grynn
Created April 9, 2010 22:36
Show Gist options
  • Save Grynn/361667 to your computer and use it in GitHub Desktop.
Save Grynn/361667 to your computer and use it in GitHub Desktop.
VBA functions for working with files
Option Explicit
Function FileDelete(Filename As String) As String
Dim fso As New FileSystemObject
On Error Resume Next
Err.Clear
Call fso.DeleteFile(Filename)
On Error GoTo 0
If Err.Number <> 0 Then
FileDelete = "Error: " & Err.Number & " " & Err.Description
End If
FileDelete = "Deleted."
End Function
Function FileExists(Filename As String)
Dim fso As New FileSystemObject
FileExists = fso.FileExists(Filename)
End Function
Function FileSize(Filename As String) As Long
Dim fso As New FileSystemObject
Dim f As File
Set f = fso.GetFile(Filename)
FileSize = f.Size
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment