?
Solved

Addition to this outlook macro. To remove "1" from the end of folder if exists.

Posted on 2010-01-11
3
Medium Priority
?
161 Views
Last Modified: 2012-05-08
Hi,

Addition to this outlook macro. To remove "1" from the end of folder if exists.
Once the below code is run...I want another check on all the sub folders and remove "1" if exists on any of the folders. So they become unique.

Regards
Sharath
0
Comment
Question by:bsharath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Dave Brett earned 2000 total points
ID: 26289975
Sharath,

Like this?

Note this code runs the last code plus does the next step. SO it should replace your last code

Cheers
Dave

Sub 25046494()
    Dim myFolder As MAPIFolder, objFolder As MAPIFolder
    Dim intItem As Integer
    Dim itm As Object
    Dim fldr As Object
    Dim intFldr As Integer

    Set myFolder = Application.GetNamespace("mapi").PickFolder
    If Not myFolder Is Nothing Then
        For intFldr = myFolder.Folders.Count To 1 Step -1
            Set fldr = myFolder.Folders(intFldr)
            If IsNumeric(Right$(fldr.Name, 1)) Then
                On Error Resume Next
                Set objFolder = myFolder.Folders(Left(fldr.Name, Len(fldr.Name) - 1))
                On Error GoTo 0

                If Not objFolder Is Nothing Then
                    For intItem = fldr.Items.Count To 1 Step -1
                        Set itm = fldr.Items(intItem)
                        itm.Move objFolder
                    Next
                    fldr.Delete
                Else
                    fldr.Name = Left$(fldr.Name, Len(fldr.Name) - 1)
                End If
            End If
        Next
    End If
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 26290199
Thanks Dave...
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 26290237
thx Sharath :)
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question