ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need directory path without filename (https://www.excelbanter.com/excel-programming/343158-need-directory-path-without-filename.html)

[email protected]

Need directory path without filename
 
Hi,

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\

Any help on this will be greatly appreciated.

Regards
Shilpa


Chip Pearson

Need directory path without filename
 
Use the Path property of the Workbook object.

Debug.Print ThisWorkbook.Path


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




wrote in message
oups.com...
Hi,

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\

Any help on this will be greatly appreciated.

Regards
Shilpa




Tom Ogilvy

Need directory path without filename
 
of what?

for an open excel file

ActiveWorkbook.Path

or
ThisWorkbook.Path

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
Hi,

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\

Any help on this will be greatly appreciated.

Regards
Shilpa




ben

Need directory path without filename
 
easy :)
msgbox activeworkbook.path
or
msgbox thisworkbook.path
or
workbooks("myworkbook.xls").path
if it returns null then it has not yet been saved
ben

--
When you lose your mind, you free your life.


" wrote:

Hi,

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\

Any help on this will be greatly appreciated.

Regards
Shilpa



Jake Marx[_3_]

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]




All times are GMT +1. The time now is 12:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com