PC Review


Reply
Thread Tools Rate Thread

VBA to find path of User created folder

 
 
The Writings
Guest
Posts: n/a
 
      13th Feb 2012
Hi There,

Is there a VBA code that I can use to find a user created folder?
A bit like serach in Windows exporer.

Kind regards
TW
 
Reply With Quote
 
 
 
 
Michael Bednarek
Guest
Posts: n/a
 
      14th Feb 2012
On Mon, 13 Feb 2012 12:40:54 -0800 (PST), The Writings wrote in
microsoft.public.outlook.program_vba:

>Is there a VBA code that I can use to find a user created folder?
> A bit like serach in Windows exporer.


If you know the exact path, you can address it with
Application.GetNamespace("MAPI").Folders("Level 1").Folders("Level 2").Folders("Level 3")
e.g.
Application.GetNamespace("MAPI").Folders("Mailbox - John Doe").Folders("Inbox").Folders("foo")

If you only know the folder name but not the path, you have to
traverse the folder tree to find it. Here is some code that will
traverse recursively a folder tree and list folder names.

Sub ListFolders(fldFolder As Variant)
Dim varFolder As Variant
Static lngLevel As Long

lngLevel = lngLevel + 1
For Each varFolder In fldFolder.Folders
Debug.Print String(lngLevel, "+") & varFolder.Name
If varFolder.Folders.Count > 0 Then
Call ListFolders(varFolder)
End If
Next
lngLevel = lngLevel - 1
End Sub

Sub testListFolders()
Call ListFolders(ActiveExplorer.CurrentFolder)
End Sub

Comparing the folder names with a search string and building a
complete path is left as an exercise for the reader. Good luck.

--
Michael Bednarek, Brisbane "ONWARD"
 
Reply With Quote
 
 
 
 
The Writings
Guest
Posts: n/a
 
      16th Feb 2012
On Feb 14, 1:34*am, Michael Bednarek <ROT13...@gtz.pbz.nh> wrote:
> On Mon, 13 Feb 2012 12:40:54 -0800 (PST), The Writings wrote in
> microsoft.public.outlook.program_vba:
>
> >Is there a VBA code that I can use to find a user created folder?
> > A bit like serach in Windows exporer.

>
> If you know the exact path, you can address it with
> * Application.GetNamespace("MAPI").Folders("Level 1").Folders("Level 2").Folders("Level 3")
> e.g.
> * Application.GetNamespace("MAPI").Folders("Mailbox - John Doe").Folders("Inbox").Folders("foo")
>
> If you only know the folder name but not the path, you have to
> traverse the folder tree to find it. Here is some code that will
> traverse recursively a folder tree and list folder names.
>
> * Sub ListFolders(fldFolder As Variant)
> * Dim varFolder As Variant
> * Static lngLevel As Long
>
> * lngLevel = lngLevel + 1
> * For Each varFolder In fldFolder.Folders
> * * Debug.Print String(lngLevel, "+") & varFolder.Name
> * * If varFolder.Folders.Count > 0 Then
> * * * Call ListFolders(varFolder)
> * * End If
> * Next
> * lngLevel = lngLevel - 1
> * End Sub
>
> * Sub testListFolders()
> * Call ListFolders(ActiveExplorer.CurrentFolder)
> * End Sub
>
> Comparing the folder names with a search string and building a
> complete path is left as an exercise for the reader. Good luck.
>
> --
> Michael Bednarek, Brisbane * * * * * * * * * * * * "ONWARD"


Thank You Michael for the coding.
I tried to run this but I do not see any output?

TW
 
Reply With Quote
 
Michael Bednarek
Guest
Posts: n/a
 
      17th Feb 2012
On Thu, 16 Feb 2012 00:57:25 -0800 (PST), The Writings wrote in
microsoft.public.outlook.program_vba:

>On Feb 14, 1:34*am, Michael Bednarek wrote:
>> On Mon, 13 Feb 2012 12:40:54 -0800 (PST), The Writings wrote in
>> microsoft.public.outlook.program_vba:
>>
>> >Is there a VBA code that I can use to find a user created folder?
>> > A bit like serach in Windows exporer.

>>
>> If you know the exact path, you can address it with
>> * Application.GetNamespace("MAPI").Folders("Level 1").Folders("Level 2").Folders("Level 3")
>> e.g.
>> * Application.GetNamespace("MAPI").Folders("Mailbox - John Doe").Folders("Inbox").Folders("foo")
>>
>> If you only know the folder name but not the path, you have to
>> traverse the folder tree to find it. Here is some code that will
>> traverse recursively a folder tree and list folder names.

[snip]
>> * * Debug.Print String(lngLevel, "+") & varFolder.Name

[snip]
>Thank You Michael for the coding.
>I tried to run this but I do not see any output?


The output of Debug.Print is shown in the VBA Editor's (Alt+F11)
Immediate Window (Ctrl+G).

--
Michael Bednarek "ONWARD"
 
Reply With Quote
 
The Writings
Guest
Posts: n/a
 
      18th Feb 2012
On Feb 17, 4:44*am, Michael Bednarek
<mbATmbednarek....@BLACKHOLESPAM.NET> wrote:
> On Thu, 16 Feb 2012 00:57:25 -0800 (PST), The Writings wrote in
> microsoft.public.outlook.program_vba:
>
>
>
>
>
>
>
> >On Feb 14, 1:34*am, Michael Bednarek wrote:
> >> On Mon, 13 Feb 2012 12:40:54 -0800 (PST), The Writings wrote in
> >> microsoft.public.outlook.program_vba:

>
> >> >Is there a VBA code that I can use to find a user created folder?
> >> > A bit like serach in Windows exporer.

>
> >> If you know the exact path, you can address it with
> >> * Application.GetNamespace("MAPI").Folders("Level 1").Folders("Level2").Folders("Level 3")
> >> e.g.
> >> * Application.GetNamespace("MAPI").Folders("Mailbox - John Doe").Folders("Inbox").Folders("foo")

>
> >> If you only know the folder name but not the path, you have to
> >> traverse the folder tree to find it. Here is some code that will
> >> traverse recursively a folder tree and list folder names.

> [snip]
> >> * * Debug.Print String(lngLevel, "+") & varFolder.Name

> [snip]
> >Thank You Michael for the coding.
> >I tried to run this but I do not see any output?

>
> The output of Debug.Print is shown in the VBA Editor's (Alt+F11)
> Immediate Window (Ctrl+G).
>
> --
> Michael Bednarek * * * * * * * * * * * * * "ONWARD"- Hide quoted text -
>
> - Show quoted text -


Thanks Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drive path vs. Network Path S:\Shared\Folder vs. \\NETWORK\USER\FO Author Microsoft Access VBA Modules 4 28th Aug 2008 05:31 PM
how to judge whether a path is relative path or absolute path thinktwice Microsoft Windows 2000 CMD Promt 20 7th May 2008 11:06 PM
set path, change path - path grayed out John Smith Windows XP Help 1 12th Feb 2005 02:56 PM
set path, change path - path grayed out John Smith Windows XP General 1 12th Feb 2005 02:56 PM
How to check output folder has been created in the network path?using VBA programming =?Utf-8?B?SGFyaW5hdGg=?= Microsoft Excel Programming 5 22nd Apr 2004 01:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:32 AM.