-
-
Create another variable named mySubFolder and dim it also as a Outlook.MAPIFolder.
Then use a loop :
[VBA]For each mySubFolder in MyFolder
'... code to alter name of mySubFolder
Next mySubFolder
[/VBA]
Just an idea.
Charlize
-
I assume you are already in outlook when you want to perform this kind of action. Here some coding. Try it first on some bogus folder with several subfolders. Subfolders have this naming convention : numbers space name (name with one item or several) ie. 1234567890123 It is me will become It is me 1234567890123 (I hope).
[VBA]Sub display_Subfolders()
'your headfolder
Dim myfolder As Outlook.MAPIFolder
'subfolders of your headfolder
Dim mysubfolder As Outlook.MAPIFolder
'array to use to hold the items as a result of split
Dim newname As Variant
'loop to use when looping items in array newname
Dim loopname As Long
'the string we create with the items of newname
Dim resultname As String
'pick your folder to process
Set myfolder = Session.PickFolder
'if error goto errorfound
On Error GoTo errorfound
'when you cancel the dialogbox without chosing a folder,
'you'll get an error
If myfolder <> False Then
'reset error trapping to not to go to errorfound
On Error GoTo 0
MsgBox "Folder chosen : " & myfolder.Name, _
vbInformation, "Headfolder ..."
For Each mysubfolder In myfolder.Folders
MsgBox "Subfolder of " & myfolder.Name & vbCrLf & _
"--- " & mysubfolder.Name & " ---", _
vbInformation, "Subfolder ..."
'split name of folder based on space
newname = Split(mysubfolder, " ")
'loop through items of newname
For loopname = LBound(newname) To UBound(newname)
'skip first item of newname (numbers)
If loopname <> 0 Then
'create new name and store it in resultname
resultname = resultname & " " & newname(loopname)
End If
'next item in array
Next loopname
'add the number which was the first item ie. 0
'standard we assume 0. if you want 1 use option base 1
'on top of this procedure (where we dim the variables)
resultname = resultname & " " & newname(0)
'rename the subfolder with new name
mysubfolder.Name = resultname
'clear resultname
resultname = ""
Next mysubfolder
Else
MsgBox "No folder has been chosen.", vbInformation, "Headfolder ..."
End If
MsgBox "Everything with your subfolders has been done.", _
vbInformation, "Final message ..."
'we don't want to see the errormessage so end this procedure
Exit Sub
errorfound:
MsgBox "Something went wrong : " & Err.number & vbCrLf & _
Err.Description & vbCrLf & _
"-> Select a folder to process. <-", vbInformation, "Error ..."
End Sub[/VBA]
Charlize
-
That is perfect Charlize...thank you very much
-Once my PC stopped working, so I kicked it......Then it started working again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules