+ Reply to Thread
Results 1 to 2 of 2

Remove certain chars

Hybrid View

  1. #1
    Registered User
    Join Date
    10-22-2015
    Location
    London
    MS-Off Ver
    Office 2013
    Posts
    1

    Question Remove certain chars

    Hi,
    i've got a macro that saves in a certain folder emails i select. It works pretty well exept for one thing. This macro has been programmed to name the file .eml according to the subject of the email. Therefore when i decide to save a forwarded email the outcome is someting like this: "I: subjectemail.eml"
    I would like to remove the chars "I:"
    Here is the code:
    Option Explicit
    
    Function BrowseForFolder(Optional OpenAt As Variant) As Variant
      Dim ShellApp As Object
      Set ShellApp = CreateObject("Shell.Application"). _
     BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
      
     On Error Resume Next
        BrowseForFolder = ShellApp.self.Path
     On Error GoTo 0
      
     Set ShellApp = Nothing
        Select Case Mid(BrowseForFolder, 2, 1)
            Case Is = ":"
                If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
            Case Is = "\"
                If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
            Case Else
                GoTo Invalid
        End Select
     Exit Function
      
    Invalid:
     BrowseForFolder = False
    End Function
    
    Public Sub SaveMessageAsMsg()
        Dim oMail As Outlook.MailItem
        Dim objItem As Object
        Dim sPath, strFolderpath As String
        Dim sName As String
        Dim enviro As String
    
        enviro = CStr(Environ("USERPROFILE"))
    
        strFolderpath = BrowseForFolder("D:\test\mails\")
        sPath = strFolderpath & "\"
    
        For Each objItem In ActiveExplorer.Selection
            If objItem.MessageClass = "IPM.Note" Then
                Set oMail = objItem
                sName = oMail.Subject
                ReplaceCharsForFileName sName, "-"
                sName = sName & ".msg"
                Debug.Print sPath & sName
                oMail.SaveAs sPath & sName, olMSG
             End If
        Next
    End Sub
    
      
    Private Sub ReplaceCharsForFileName(sName As String, _
      sChr As String _
    )
      sName = Replace(sName, "'", sChr)
      sName = Replace(sName, "*", sChr)
      sName = Replace(sName, "/", sChr)
      sName = Replace(sName, "\", sChr)
      sName = Replace(sName, ":", sChr)
      sName = Replace(sName, "?", sChr)
      sName = Replace(sName, Chr(34), sChr)
      sName = Replace(sName, "<", sChr)
      sName = Replace(sName, ">", sChr)
      sName = Replace(sName, "|", sChr)
      
    End Sub

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,192

    Re: Remove certain chars

    This code does not work for me. After it prompts the user for a folder, it stops execution.

    When I bypass that code and just set the folder path, I do not get the results you describe. I am not getting "I:" at the beginning of the file name.

    Can you give an example of an email subject that causes you to get this result?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Remove Chars in Call Based on Condition
    By FallingDown in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2014, 06:20 AM
  2. [SOLVED] Help! Remove numbers and all chars to left of the numbers.
    By trouble085 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-08-2012, 09:54 PM
  3. Remove iNdex chars From Left
    By teodormircea in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-21-2009, 08:19 AM
  4. Chars in macro
    By 63falcon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2007, 11:46 AM
  5. Replies: 2
    Last Post: 03-16-2006, 11:15 AM
  6. Removing last three chars
    By teresa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2005, 09:06 PM
  7. remove blanks from a string of chars within a cell?
    By rayhollidge in forum Excel General
    Replies: 3
    Last Post: 01-07-2005, 11:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1