Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
pk pk is offline
external usenet poster
 
Posts: 5
Default Obtain full path to a directory

Hello, can someone help me please?

I am using VBA in Excel XP with Windows 2000.

I need to be able to return the full path to a
subdirectory given only the drive and the directory name
sought (i.e. not the path in between).

For example, I know the drive is: \\cdl\ofl\users\

I know the subdirectory I want is named: Aug03

I need code to return the full path to the subdirectory
which may be something like:

\\cdl\ofl\users\msm\work\losses\Aug03\

or like: \\cdl\ofl\users\ldw\fieldwork\Aug03\

There are two to four files in the target directory and
their names are dynamic.

Your example code would be most appreciated...thanks in
advance...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Obtain full path to a directory


Following should get you u on your way

Note that you'll need a reference to
"Microsoft scripting runtime"

'--------------------------------
Option Explicit
Option Compare Text

Dim myFolders As Collection

Sub FindFolder()
Dim fso As New Scripting.FileSystemObject
Dim s As String, itm As Variant

Set myFolders = New Collection
Call FindSubFolders(fso.GetFolder("C:\"), "*\Aug03")
If myFolders.Count 0 Then
s = " Found:" & vbNewLine
For Each itm In myFolders
s = s & itm & vbNewLine
Next
Else
s = "None found"
End If
MsgBox s
End Sub

Sub FindSubFolders(Folder As Scripting.Folder, sMask As String)
Dim subfolder As Scripting.Folder
On Error Resume Next
For Each subfolder In Folder.SubFolders
If subfolder.Path Like sMask Then myFolders.Add subfolder.Path
FindSubFolders subfolder, sMask
Next
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"pk" wrote:

Hello, can someone help me please?

I am using VBA in Excel XP with Windows 2000.

I need to be able to return the full path to a
subdirectory given only the drive and the directory name
sought (i.e. not the path in between).

For example, I know the drive is: \\cdl\ofl\users\

I know the subdirectory I want is named: Aug03

I need code to return the full path to the subdirectory
which may be something like:

\\cdl\ofl\users\msm\work\losses\Aug03\

or like: \\cdl\ofl\users\ldw\fieldwork\Aug03\

There are two to four files in the target directory and
their names are dynamic.

Your example code would be most appreciated...thanks in
advance...



  #3   Report Post  
Posted to microsoft.public.excel.programming
pk pk is offline
external usenet poster
 
Posts: 1
Default Obtain full path to a directory

THANKS SO MUCH! THAT'S EXACTLY WHAT I NEEDED!


-----Original Message-----

Following should get you u on your way

Note that you'll need a reference to
"Microsoft scripting runtime"

'--------------------------------
Option Explicit
Option Compare Text

Dim myFolders As Collection

Sub FindFolder()
Dim fso As New Scripting.FileSystemObject
Dim s As String, itm As Variant

Set myFolders = New Collection
Call FindSubFolders(fso.GetFolder("C:\"), "*\Aug03")
If myFolders.Count 0 Then
s = " Found:" & vbNewLine
For Each itm In myFolders
s = s & itm & vbNewLine
Next
Else
s = "None found"
End If
MsgBox s
End Sub

Sub FindSubFolders(Folder As Scripting.Folder, sMask As

String)
Dim subfolder As Scripting.Folder
On Error Resume Next
For Each subfolder In Folder.SubFolders
If subfolder.Path Like sMask Then myFolders.Add

subfolder.Path
FindSubFolders subfolder, sMask
Next
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"pk" wrote:

Hello, can someone help me please?

I am using VBA in Excel XP with Windows 2000.

I need to be able to return the full path to a
subdirectory given only the drive and the directory

name
sought (i.e. not the path in between).

For example, I know the drive is: \\cdl\ofl\users\

I know the subdirectory I want is named: Aug03

I need code to return the full path to the subdirectory
which may be something like:

\\cdl\ofl\users\msm\work\losses\Aug03\

or like: \\cdl\ofl\users\ldw\fieldwork\Aug03\

There are two to four files in the target directory and
their names are dynamic.

Your example code would be most appreciated...thanks in
advance...



.

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
Cell reference to make a directory path Dan Deschambault Excel Worksheet Functions 10 July 25th 07 07:25 PM
Excel 2k3 query path to current directory busypgmr Excel Discussion (Misc queries) 1 September 5th 06 10:05 PM
Dynamic directory path Newbie Excel Discussion (Misc queries) 1 April 24th 06 04:56 PM
Target directory & Path Param Excel Worksheet Functions 0 March 28th 06 01:52 AM
How do I insert the directory path in my Excel file? Insert a Directory Path in Header/Footer Excel Worksheet Functions 2 February 4th 05 09:23 PM


All times are GMT +1. The time now is 09:31 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"