Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Working with application path


Given the following path:

s = Excel.ActiveWorkbook.Path

how can I find the parent folder 3 levels up?


Eg if s = p:\paydata\hrimp\library\monthlystats\2005\12\Chie fExec

i want to be able to return p:\paydata\hrimp\library\monthlystats

I could do it by searching for the \ characters from the end of the
string, but it is there any easier way to do this?

Nirmal Singh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Working with application path

An easy way would be to use the FileSystemObject in the Scripting
library. In VBA, go to the Tools menu, choose References, and put
a check next to "Microsoft Scripting Runtime". Then, use code
like

Dim FSO As Scripting.FileSystemObject
Dim Fldr As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set Fldr = FSO.GetFolder(ActiveWorkbook.Path)
Set Fldr = Fldr.ParentFolder.ParentFolder
Debug.Print Fldr.Path


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




"Nirmal Singh" wrote in
message ...

Given the following path:

s = Excel.ActiveWorkbook.Path

how can I find the parent folder 3 levels up?


Eg if s =
p:\paydata\hrimp\library\monthlystats\2005\12\Chie fExec

i want to be able to return
p:\paydata\hrimp\library\monthlystats

I could do it by searching for the \ characters from the end of
the
string, but it is there any easier way to do this?

Nirmal Singh



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Working with application path

On Wed, 14 Dec 2005 13:16:23 -0600, "Chip Pearson"
wrote:

An easy way would be to use the FileSystemObject in the Scripting
library. In VBA, go to the Tools menu, choose References, and put
a check next to "Microsoft Scripting Runtime". Then, use code
like

Thanks Chip, that is exactly what I needed.

Nirmal Singh

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Working with application path

Try using GetParentFolderName.

As in the following function:

Function GetParentFoder3Up(ByVal s As String) As String
Dim fs As Variant
Set fs = CreateObject("Scripting.FileSystemObject")

s = fs.GetParentfoldername(s)
s = fs.GetParentfoldername(s)
GetParentFoder3Up = fs.GetParentfoldername(s)
Set fs = Nothing

End Function

HTHs.

"Nirmal Singh" wrote:


Given the following path:

s = Excel.ActiveWorkbook.Path

how can I find the parent folder 3 levels up?


Eg if s = p:\paydata\hrimp\library\monthlystats\2005\12\Chie fExec

i want to be able to return p:\paydata\hrimp\library\monthlystats

I could do it by searching for the \ characters from the end of the
string, but it is there any easier way to do this?

Nirmal Singh


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Smart Application.Path helmekki[_95_] Excel Programming 0 October 13th 05 01:19 PM
How do I set a default path when using Application.GetOpenFilename pkohler[_7_] Excel Programming 2 July 13th 04 07:17 PM
set path for Application.Run zSplash Excel Programming 1 January 28th 04 09:41 PM
Application.Path in Excel 2k and 2002 Simon[_12_] Excel Programming 1 November 12th 03 05:51 PM
Application.Path Simon Davies Excel Programming 1 November 12th 03 04:52 PM


All times are GMT +1. The time now is 02:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"