Creating a Select Case for a directory of folders

Status
Not open for further replies.

nathandavies

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I have an 2 issue's with the following code, which i was hoping someone could help me with....

1. The code only allows me to input the full folder name to save the email on my server, i would like it to use just the number element. This is a general folder name: "13469 - ABB - Project Grange UK". I would like the code to just find the folder directory based on "13469"...is this possible?

2.My code does not take into account that the project folder is a sub folder of a main folder. I need to create a code that loops through the main folders which are a set out : "13400 - 13499" but range from "0001 - 0100" up to "5000 - 5900"

This is an example of one project layout....P:\Group\JOBDATA\13400 - 13499\13469 - ABB - Project Grange UK"

Code:
Sub JOBDATA_SAVE_EMAIL()
    'The unique number of your project
    Dim ProjectID As String
    'the mail we want to process
    Dim objItem As Outlook.MailItem
    'question for saving, use subject to save
    Dim strPrompt As String, strname As String, emailto As String, emailfrom As String
    'variables for the replacement of illegal characters
    Dim sreplace As String, mychar As Variant, strdate As String
    'mypath as variant when using browsefolder function (false is boolean and no string)
    Dim mypath As Variant
    'put active mail in this object holder
    Set objItem = Outlook.ActiveExplorer.Selection.Item(1)
    'check if it's an email
    If objItem.Class = olMail Then
        mypath = ""
        'check on subject
        If objItem.Subject <> vbNullString Then
            strname = objItem.Subject
        Else
            strname = "No_Subject"
        End If
        'ask until a projectid is given
        Do Until Right(mypath, 1) <> "\" And mypath <> vbNullString
            mypath = "P:\Group\JOBDATA\" & InputBox("Give EXISTING projectID ...", "Saving to Project ...")
        Loop
        'add ending slash
        mypath = mypath & "\"
        'select if the selected mail is located in the inbox or sent items folder
        Select Case objItem.Parent
            Case Outlook.Session.GetDefaultFolder(olFolderInbox)
                'change saving path accordingly
                mypath = mypath & "Correspondence\Email.In\"
                emailfrom = objItem.Sender
            Case Outlook.Session.GetDefaultFolder(olFolderSentMail)
                mypath = mypath & "Correspondence\Email.Out\"
                emailto = objItem.To
        End Select
        strdate = objItem.ReceivedTime
        'define the character that will replace illegal characters
        sreplace = "_"
        'create an array to loop through illegal characters (saves lines)
        For Each mychar In Array("/", "\", ":", "?", Chr(34), "<", ">", "¦")
        'do the replacement for each character that's illegal
            If emailfrom <> vbNullString Then
                emailfrom = Replace(emailfrom, mychar, sreplace)
            End If
            If emailto <> vbNullString Then
                emailto = Replace(emailto, mychar, sreplace)
            End If
            strname = Replace(strname, mychar, sreplace)
            strdate = Replace(strdate, mychar, sreplace)
        Next mychar
        If emailto <> vbNullString Then
        'emailto not empty means outgoing mail
        'strdate is based on the european date system (dd/mm/yyyy). splitting text gives an array
        'starting with 0. In this case, we split on space to get date alone and not the time
        '(2) before & contains the year
        '(1) before & contains the month
        '(0) before & contains the day
        '
        'the (0) before the , contains the first part of date and time of the string "21_11_2014 12_30_55"
        'since we split the first time with the splitseparator space we get "21_11_2014"
        'then we use the split with separator _ to get 3 parts of the date
            objItem.SaveAs mypath & _
                Split(Split(strdate, " ")(0), "_")(2) & "-" & _
                Split(Split(strdate, " ")(0), "_")(1) & "-" & _
                Split(Split(strdate, " ")(0), "_")(0) & " - " & _
                Split(strdate, " ")(1) & " -- " & emailto & " -- " & strname & ".msg", olMSG
        Else
        'emailto empty means received email = inbox
            objItem.SaveAs mypath & _
                Split(Split(strdate, " ")(0), "_")(2) & "-" & _
                Split(Split(strdate, " ")(0), "_")(1) & "-" & _
                Split(Split(strdate, " ")(0), "_")(0) & " - " & _
                Split(strdate, " ")(1) & " -- " & emailfrom & " -- " & strname & ".msg", olMSG
        End If
        'If you answer is yes on this question, the selected email will be deleted from the mailfolder
        'in outlook.
        If MsgBox("Delete saved email ?", vbYesNo, "Deleting saved email ?") = vbYes Then
            objItem.Delete
        End If
    End If
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
Fozzie Bear Outlook 2016 Creating a shared local Contacts folder Using Outlook 2
R Creating a user defined function Outlook VBA and Custom Forms 3
M Creating an RSS Feed **FROM** Outlook 2013 Calendar. Using Outlook 5
O How to prevent CC from showing when creating a new mail? Using Outlook 1
N Creating a button or link to a form in the Organizational Forms Library Outlook VBA and Custom Forms 3
B Creating an email with the list of tasks Outlook VBA and Custom Forms 0
L Creating drafts when I thought I was sending Using Outlook 1
R Would creating a new profile cause Outlook to download all the old mails from the server? Using Outlook 1
A Creating Progress Bar or Status Bar Update Outlook VBA and Custom Forms 0
T Outlook creating a folder named: "Unwanted" Using Outlook 3
M Outlook 2007 Contacts Glitch: Creating a new email Using Outlook 1
Liza Creating a rule in outlook to filter messages Using Outlook 0
A Are categories still recommended for creating local distribution lists? Using Outlook 3
S Creating Email - Selecting Pre-Defined Text Using Outlook 2
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
M Creating Outlook Appointments from Excel Cells Outlook VBA and Custom Forms 1
N Creating New Profile Using Outlook 0
Y Creating custom appointment request form with multiple mail recipients Outlook VBA and Custom Forms 5
M creating email from contact file = 3 emails in To field Using Outlook 3
P Recover / Extract Rules from standalone PST file creating RWZ file Using Outlook 2
A Creating an outlook rule to forward an email with a specific message Using Outlook 1
I Creating meeting invite with disabled tentative button Outlook VBA and Custom Forms 5
E Creating email templates for organizational use Using Outlook 0
N Creating or changing the main new mail message template in Outlook 2010 Using Outlook 2
D Creating custom view with VBA Outlook VBA and Custom Forms 2
J Outlook creating unwanted rule on its own Using Outlook 1
R Creating a Room Mailbox with Exchange Online Outlook VBA and Custom Forms 0
A Creating a rule on “Deleted items” folder Using Outlook 1
CMG73 Creating templates with predefined subject and CC Using Outlook 1
G Creating Contact Sub Folders Using Outlook 2
Rupert Dragwater creating gmail account in Outlook 2013 Using Outlook 7
2 creating custom stationery Using Outlook 2
A Help creating macro for conditional formatting settings Using Outlook 8
Fozzie Bear Creating Custom Meeting Form Outlook VBA and Custom Forms 6
U Creating a (This computer only) folder within an IMAP account directory Using Outlook 1
A Creating archive rule on the clients by script/ Outlook VBA and Custom Forms 3
J Creating a URL from a message body excerpt before forwarding Using Outlook 2
B Need Help Creating Email Based on Subject w Address in Body Outlook VBA and Custom Forms 1
A Creating rule to create week folder and transfer mail using alert Using Outlook 3
J Creating an "isolated" shared calendar in Outlook Outlook VBA and Custom Forms 1
L Creating a Task from Email and Attaching Original Email Outlook VBA and Custom Forms 6
S Creating custom rule to move if "NAME" is in body but ignore the phrase "Hi NAME" in the search Using Outlook 2
witzker Outlook bug when creating a user defined contact form? Using Outlook 1
G Creating an Outlook Rule using Internet Header time Using Outlook 1
Wotme Creating a Outlook task in Excel Using Outlook 7
V Need to add some text in subject while creating new mails - NEED VB CODINGS Using Outlook 4
G Questions on creating Outlook forms Using Outlook 0
P Creating custom contact forms Using Outlook 2
K Outlook 2010 creating extremely large PST files for IMAP accounts Using Outlook 3
J Troubleshooting Creating New Outlook Account Using Outlook 1
Similar threads


















































Top