Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

3 Autoreply codes need to be changed as to get the firstname in the body.

Posted on 2009-04-03
4
Medium Priority
?
179 Views
Last Modified: 2012-05-06
Hi,

3 Autoreply codes need to be changed as to get the firstname in the body.

Code from Chris...

Need the change as
Hi Firstname,
at present i get
Hi,Firstname

Regards
Sharath
Sub AutoReply1()
    Dim olkItem As Object, _
        olkMsg As Outlook.MailItem, _
        olkRecip As Object, _
        arrLines As Variant, _
        varLine As Variant, _
        strName As String
    For Each olkItem In Application.ActiveExplorer.Selection
        If olkItem.Class = olMail Then
            arrLines = Split(olkItem.Body, vbCrLf)
            For Each varLine In arrLines
                If InStr(1, varLine, "User:") Then
                    strName = Mid(varLine, InStr(1, varLine, "\") + 1)
                    strName = Trim(strName)
                    strName = Replace(strName, vbCr, "")
                    strName = Replace(strName, vbLf, "")
                    Set olkMsg = Application.CreateItem(olMailItem)
                    With olkMsg
                        Set olkRecip = .Recipients.Add(strName)
                        olkRecip.Resolve
                        strName = Mid(olkRecip.Name, 1, InStr(1, olkRecip.Name, " ") - 1)
                        'Change the subject on the next line'
                        .Subject = "Retricted File\Application"
                        .BodyFormat = olFormatHTML
                        'Change the message body on the next line'
                        .HTMLBody = "Hi, " & strName & "<br><br> Please reply back once removed.<br><br>Regards<br>Sharath<br>(I)<br><hr><br>" & olkItem.HTMLBody
                        .Display
                    End With
                    Exit For
                End If
            Next
        End If
    Next
    Set olkItem = Nothing
    Set olkMsg = Nothing
    Set olkRecip = Nothing
End Sub
 
 
Sub AutoReply2()
    Dim olkItem As Object, _
        olkMsg As Outlook.MailItem, _
        olkRecip As Object, _
        arrLines As Variant, _
        varLine As Variant, _
        strName As String
    For Each olkItem In Application.ActiveExplorer.Selection
        If olkItem.Class = olMail Then
            arrLines = Split(olkItem.Body, vbCrLf)
            For Each varLine In arrLines
                If InStr(1, varLine, "User:") Then
                    strName = Mid(varLine, InStr(1, varLine, "\") + 1)
                    strName = Trim(strName)
                    strName = Replace(strName, vbCr, "")
                    strName = Replace(strName, vbLf, "")
                    Set olkMsg = Application.CreateItem(olMailItem)
                    With olkMsg
                        Set olkRecip = .Recipients.Add(strName)
                        olkRecip.Resolve
                        strName = Mid(olkRecip.Name, 1, InStr(1, olkRecip.Name, " ") - 1)
                        'Change the subject on the next line'
                        .Subject = "Restricted USB Usage"
                        .BodyFormat = olFormatHTML
                        'Change the message body on the next line'
                        .HTMLBody = "Hi, " & strName & "<br><br>checks.<br><br>Regards<br>Sharath <br>(I)<br><hr><br>" & olkItem.HTMLBody
                        .Display
                    End With
                    Exit For
                End If
            Next
        End If
    Next
    Set olkItem = Nothing
    Set olkMsg = Nothing
    Set olkRecip = Nothing
End Sub
 
 
Sub AutoReply3()
Const FilePathandName As String = "D:\Machinename.txt"
'Const FilePathandName As String = "c:\deleteme\mcusers.txt"
Dim inputFile As Object
Dim fso As Object
Dim dic As Object
Dim arrCount As Long
Dim strName As String
Dim strMC As String
Dim strAddy As String
    Dim olkItem As Object, _
        olkMsg As Outlook.MailItem, _
        olkRecip As Object, _
        arrLines As Variant, _
        varLine As Variant, _
        strTo As String, _
        arrTo() As String
    
    Set fso = CreateObject("scripting.filesystemobject")
    If fso.FileExists(FilePathandName) Then
        Set inputFile = fso.OpenTextFile(FilePathandName, 1, TristateTrue)
        strTo = inputFile.ReadAll
        arrTo = Split(strTo, vbCrLf)
        Set inputFile = Nothing
    Else
        Set inputFile = Nothing
        strTo = ""
    End If
    Set fso = Nothing
    If strTo <> "" Then
        Set dic = CreateObject("scripting.dictionary")
        For arrCount = 0 To UBound(arrTo)
            strName = arrTo(arrCount)
            If InStr(strName, ";") > 0 Then
                strMC = LCase(Left(strName, InStr(strName, ";") - 1))
                strAddy = LCase(Right(strName, Len(strName) - InStr(strName, ";")))
                If Not dic.Exists(strMC) Then
                    dic.Add strMC, strAddy
                End If
            End If
        Next
    End If
    For Each olkItem In Application.ActiveExplorer.Selection
        If olkItem.Class = olMail Then
            arrLines = Split(olkItem.Body, vbCrLf)
            For Each varLine In arrLines
                If InStr(1, varLine, "Machine:") Then
                    strName = LCase(Mid(varLine, InStr(1, varLine, ":") + 1))
                    strName = Trim(strName)
                    strName = Replace(strName, vbCr, "")
                    strName = Replace(strName, vbLf, "")
                    If dic.Exists(strName) Then
                        strTo = dic(strName)
                    Else
                        strTo = ""
                    End If
                    If strTo = "" Then Exit For
                    Set olkMsg = Application.CreateItem(olMailItem)
                    With olkMsg
                        Set olkRecip = .Recipients.Add(strTo)
                        olkRecip.Resolve
                        If Not olkRecip.Resolved Then
                            strName = Mid(strTo, 1, InStr(1, strTo, "@") - 1)
                            If InStr(strName, ".") > 0 Then strName = Left(strName, InStr(strName, ".") - 1)
                            If InStr(strName, " ") > 0 Then strName = Left(strName, InStr(strName, " ") - 1)
                        Else
                            strName = Mid(olkRecip.Name, 1, InStr(1, olkRecip.Name, " ") - 1)
                        End If
                        strName = UCase(Left(strName, 1)) & LCase(Right(strName, Len(strName) - 1))
                        'Change the subject on the next line'
                        .Subject = "Subject data"
                        .BodyFormat = olFormatHTML
                        'Change the message body on the next line'
                        .HTMLBody = "Hi " & strName & ",<br><br>This is the matter in the body.<br><br>Regards<br>Sharath<br>(1)<br><hr><br>" & olkItem.HTMLBody
                        .Display
                    End With
                    Exit For
                End If
            Next
        End If
    Next
    Set olkItem = Nothing
    Set olkMsg = Nothing
    Set olkRecip = Nothing
End Sub

Open in new window

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
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 24057425
Didn't realise these were the ones you were interested in!, thought it was a different application.

Any better?

Chris
Sub AutoReply1()
    Dim olkItem As Object, _
        olkMsg As Outlook.MailItem, _
        olkRecip As Object, _
        arrLines As Variant, _
        varLine As Variant, _
        strName As String
    For Each olkItem In Application.ActiveExplorer.Selection
        If olkItem.Class = olMail Then
            arrLines = Split(olkItem.Body, vbCrLf)
            For Each varLine In arrLines
                If InStr(1, varLine, "User:") Then
                    strName = Mid(varLine, InStr(1, varLine, "\") + 1)
                    strName = Trim(strName)
                    strName = Replace(strName, vbCr, "")
                    strName = Replace(strName, vbLf, "")
                    Set olkMsg = Application.CreateItem(olMailItem)
                    With olkMsg
                        Set olkRecip = .Recipients.Add(strName)
                        olkRecip.Resolve
                        strName = Mid(olkRecip.Name, 1, InStr(1, olkRecip.Name, " ") - 1)
                        'Change the subject on the next line'
                        .Subject = "Retricted File\Application"
                        .BodyFormat = olFormatHTML
                        'Change the message body on the next line'
                        .HTMLBody = "Hi " & strName & ",<br><br> Please reply back once removed.<br><br>Regards<br>Sharath<br>(I)<br><hr><br>" & olkItem.HTMLBody
                        .Display
                    End With
                    Exit For
                End If
            Next
        End If
    Next
    Set olkItem = Nothing
    Set olkMsg = Nothing
    Set olkRecip = Nothing
End Sub
 
 
Sub AutoReply2()
    Dim olkItem As Object, _
        olkMsg As Outlook.MailItem, _
        olkRecip As Object, _
        arrLines As Variant, _
        varLine As Variant, _
        strName As String
    For Each olkItem In Application.ActiveExplorer.Selection
        If olkItem.Class = olMail Then
            arrLines = Split(olkItem.Body, vbCrLf)
            For Each varLine In arrLines
                If InStr(1, varLine, "User:") Then
                    strName = Mid(varLine, InStr(1, varLine, "\") + 1)
                    strName = Trim(strName)
                    strName = Replace(strName, vbCr, "")
                    strName = Replace(strName, vbLf, "")
                    Set olkMsg = Application.CreateItem(olMailItem)
                    With olkMsg
                        Set olkRecip = .Recipients.Add(strName)
                        olkRecip.Resolve
                        strName = Mid(olkRecip.Name, 1, InStr(1, olkRecip.Name, " ") - 1)
                        'Change the subject on the next line'
                        .Subject = "Restricted USB Usage"
                        .BodyFormat = olFormatHTML
                        'Change the message body on the next line'
                        .HTMLBody = "Hi " & strName & ",<br><br>checks.<br><br>Regards<br>Sharath <br>(I)<br><hr><br>" & olkItem.HTMLBody
                        .Display
                    End With
                    Exit For
                End If
            Next
        End If
    Next
    Set olkItem = Nothing
    Set olkMsg = Nothing
    Set olkRecip = Nothing
End Sub
 
 
Sub AutoReply3()
Const FilePathandName As String = "D:\Machinename.txt"
'Const FilePathandName As String = "c:\deleteme\mcusers.txt"
Dim inputFile As Object
Dim fso As Object
Dim dic As Object
Dim arrCount As Long
Dim strName As String
Dim strMC As String
Dim strAddy As String
    Dim olkItem As Object, _
        olkMsg As Outlook.MailItem, _
        olkRecip As Object, _
        arrLines As Variant, _
        varLine As Variant, _
        strTo As String, _
        arrTo() As String
    
    Set fso = CreateObject("scripting.filesystemobject")
    If fso.FileExists(FilePathandName) Then
        Set inputFile = fso.OpenTextFile(FilePathandName, 1, TristateTrue)
        strTo = inputFile.ReadAll
        arrTo = Split(strTo, vbCrLf)
        Set inputFile = Nothing
    Else
        Set inputFile = Nothing
        strTo = ""
    End If
    Set fso = Nothing
    If strTo <> "" Then
        Set dic = CreateObject("scripting.dictionary")
        For arrCount = 0 To UBound(arrTo)
            strName = arrTo(arrCount)
            If InStr(strName, ";") > 0 Then
                strMC = LCase(Left(strName, InStr(strName, ";") - 1))
                strAddy = LCase(Right(strName, Len(strName) - InStr(strName, ";")))
                If Not dic.Exists(strMC) Then
                    dic.Add strMC, strAddy
                End If
            End If
        Next
    End If
    For Each olkItem In Application.ActiveExplorer.Selection
        If olkItem.Class = olMail Then
            arrLines = Split(olkItem.Body, vbCrLf)
            For Each varLine In arrLines
                If InStr(1, varLine, "Machine:") Then
                    strName = LCase(Mid(varLine, InStr(1, varLine, ":") + 1))
                    strName = Trim(strName)
                    strName = Replace(strName, vbCr, "")
                    strName = Replace(strName, vbLf, "")
                    If dic.Exists(strName) Then
                        strTo = dic(strName)
                    Else
                        strTo = ""
                    End If
                    If strTo = "" Then Exit For
                    Set olkMsg = Application.CreateItem(olMailItem)
                    With olkMsg
                        Set olkRecip = .Recipients.Add(strTo)
                        olkRecip.Resolve
                        If Not olkRecip.Resolved Then
                            strName = Mid(strTo, 1, InStr(1, strTo, "@") - 1)
                            If InStr(strName, ".") > 0 Then strName = Left(strName, InStr(strName, ".") - 1)
                            If InStr(strName, " ") > 0 Then strName = Left(strName, InStr(strName, " ") - 1)
                        Else
                            strName = Mid(olkRecip.Name, 1, InStr(1, olkRecip.Name, " ") - 1)
                        End If
                        strName = UCase(Left(strName, 1)) & LCase(Right(strName, Len(strName) - 1))
                        'Change the subject on the next line'
                        .Subject = "Subject data"
                        .BodyFormat = olFormatHTML
                        'Change the message body on the next line'
                        .HTMLBody = "Hi " & strName & ",<br><br>This is the matter in the body.<br><br>Regards<br>Sharath<br>(1)<br><hr><br>" & olkItem.HTMLBody
                        .Display
                    End With
                    Exit For
                End If
            Next
        End If
    Next
    Set olkItem = Nothing
    Set olkMsg = Nothing
    Set olkRecip = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24057449
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24057473
I should have expected that!  I'll look in a little while.

Chris
0
 
LVL 11

Author Comment

by:bsharath
ID: 24057486
Thanks

Can you post the solution from here to this Q...
http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_24238013.html
So i can close. As you have solved that issue also in this code change itsself... :-)))
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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