Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Returning folder name

24 views
Skip to first unread message

Tony Balazs

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
How can I return as a string the name of the folder in which an Excel
97 doc is contained?

Thanks for any suggestions.

Tony.

Dave

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
Tony,

> How can I return as a string the name of the folder in which an Excel
> 97 doc is contained?

The property ActiveWorkbook.Path will return the path of the active
work book. To extract the folder only from a full path, use a function
such as this:

Function GetFolder(SourcePath As String) As String
'extracts the folder name from a complete document path
Dim x, oldx As Integer

x = 1

Do While True
x = InStr(x + 1, SourcePath, Application.PathSeparator)
If x = 0 Then
Exit Do
End If
oldx = x
Loop

GetFolder = Left(SourcePath, oldx - 1)
End Function

e.g to return the path of the active document, use:

Sub TestFunction
Msgbox(GetFolder(ActiveWorkbook.FullPath))
End Sub

(obviously, in this case using ActiveWorkbook.Path would return the
same thing, but its only an example!)

HTH,
Dave.

In article <38fad88b...@nntp.netcomuk.co.uk>,


Sent via Deja.com http://www.deja.com/
Before you buy.

0 new messages