View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Need directory path without filename

Hi Shilpa,

wrote:
Is there a way to find out only the directory path without filename
using VBA macro. I came across macros that will spit out only filename
from the full path.

Example: D:\Documents\ExcelPrograms\


If you're looking for an open workbook's path, then take Chip's advice and
use the Path property. If you have a full path/filename string and want the
path only, you could use the FileSystemObject:

Public Function gsGetPath(rsFilePath As String) As String
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(rsFilePath) Then
gsGetPath = fso.GetFile(rsFilePath).ParentFolder.Path & _
Application.PathSeparator
End If

Set fso = Nothing
End Function

Alternatively, you could use InStrRev to find the last occurence of the
backslash, then use Left$() to get the path from there.

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]