Skip to content

Instantly share code, notes, and snippets.

@iseebi
Created May 18, 2011 05:58
Show Gist options
  • Save iseebi/978053 to your computer and use it in GitHub Desktop.
Save iseebi/978053 to your computer and use it in GitHub Desktop.
Excel VBA Macro for Filename processing
Option Explicit
Function dirname(ByVal inVal As String, Optional directorySeparater As String = "/") As String
Dim basenameStr As String
basenameStr = basename(inVal, directorySeparater)
If basenameStr <> inVal Then
dirname = Left(inVal, Len(inVal) - Len(basenameStr) - 1)
Else
dirname = "."
End If
End Function
Function basename(ByVal inVal As String, Optional directorySeparater As String = "/") As String
Dim index As Integer
index = InStrRev(inVal, directorySeparater)
If index > 0 Then
basename = Mid(inVal, index + 1)
Else
basename = Mid(inVal, index + 1)
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment