Gianni
New Member
- OS Version(s)
- Windows
- Outlook version
- Outlook 365 64 bit
- Email Account
- Exchange Server
Operating system:: Windows 10
Outlook version: Outlook 365 64bit
Email type or host: giancarlo.cecconi@meccalte.it
Outlook version: Outlook 365 64bit
Email type or host: giancarlo.cecconi@meccalte.it
Good morning to all,
I'm doig my first step in VBA Outlook and they are not so "sure". I found some solutions and I try to adapt it to my issue. I need to reply a message (selected) and remove one empty space.
I need to remove CR before signature (Highligted in green)
The code "promise" to do it, but it do not run. What I'm doing wrong?
Here is my code
Sub ReplyMSG()
Dim olMail As Outlook.MailItem
Dim olReply As MailItem ' Reply
Dim olRecip As Recipient ' Add Recipient
Dim StrName As String
Dim signature As String
For Each olMail In Application.ActiveExplorer.Selection
Set olReply = olMail.ReplyAll
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Set olMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp
' \s* = invisible spaces
' \d* = match digits
' \w* = match alphanumeric
With Reg1
.Pattern = "Standard Code\s*(\w*)\s*"
.Global = True
End With
If Reg1.test(olMail.Subject) Then
Set M1 = Reg1.Execute(olMail.Subject)
For Each M In M1
' M.SubMatches(1) is the (\w*) in the pattern
' use M.SubMatches(2) for the second one if you have two (\w*)
Debug.Print M.SubMatches(0)
StrName = StrConv(M.SubMatches(0), vbProperCase)
Next
End If
If StrName = "" Then
With Reg1
.Pattern = "OOSOF\s*(\w*)\s*"
.Global = True
End With
If Reg1.test(olMail.Subject) Then
Set M1 = Reg1.Execute(olMail.Subject)
For Each M In M1
' M.SubMatches(1) is the (\w*) in the pattern
' use M.SubMatches(2) for the second one if you have two (\w*)
Debug.Print M.SubMatches(0)
StrName = StrConv(M.SubMatches(0), vbProperCase)
Next
End If
With olReply
.BodyFormat = 2
.Display
'deletes blank space present before signature
signature = Replace(olReply.HTMLBody, "<p ><o
> </o
></p>", "")
'removes entire e-mail contents and then closes with discard
olReply.HTMLBody = Replace(olReply.HTMLBody, olReply.HTMLBody, "")
olReply.Close 1
End With
On Error Resume Next
With olReply
.HTMLBody = "Ciao " & StrName & "," & "<br><br>" & "dati contabili creati. " & "<br><br><br>" & "Cordiali saluti" & signature ' & .HTMLBody
.Display 'or use .Send
End With
On Error GoTo 0
Else:
With olReply
.BodyFormat = 2
.Display
'deletes blank space present before signature
signature = Replace(olReply.HTMLBody, "<p ><o
> </o
></p>", "")
'removes entire e-mail contents and then closes with discard
olReply.HTMLBody = Replace(olReply.HTMLBody, olReply.HTMLBody, "")
olReply.Close 1
End With
On Error Resume Next
With olReply
.HTMLBody = "Ciao " & StrName & "," & "<br><br>" & "dati contabili creati. " & "<br><br><br>" & "Cordiali saluti" & signature ' & .HTMLBody
.Display 'or use .Send
End With
On Error GoTo 0
End If
Next olMail
Set olReply = Nothing
Set olMail = Nothing
End Sub
Thanks for Help me
Gianni
I'm doig my first step in VBA Outlook and they are not so "sure". I found some solutions and I try to adapt it to my issue. I need to reply a message (selected) and remove one empty space.
I need to remove CR before signature (Highligted in green)

The code "promise" to do it, but it do not run. What I'm doing wrong?
Here is my code
Sub ReplyMSG()
Dim olMail As Outlook.MailItem
Dim olReply As MailItem ' Reply
Dim olRecip As Recipient ' Add Recipient
Dim StrName As String
Dim signature As String
For Each olMail In Application.ActiveExplorer.Selection
Set olReply = olMail.ReplyAll
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Set olMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp
' \s* = invisible spaces
' \d* = match digits
' \w* = match alphanumeric
With Reg1
.Pattern = "Standard Code\s*(\w*)\s*"
.Global = True
End With
If Reg1.test(olMail.Subject) Then
Set M1 = Reg1.Execute(olMail.Subject)
For Each M In M1
' M.SubMatches(1) is the (\w*) in the pattern
' use M.SubMatches(2) for the second one if you have two (\w*)
Debug.Print M.SubMatches(0)
StrName = StrConv(M.SubMatches(0), vbProperCase)
Next
End If
If StrName = "" Then
With Reg1
.Pattern = "OOSOF\s*(\w*)\s*"
.Global = True
End With
If Reg1.test(olMail.Subject) Then
Set M1 = Reg1.Execute(olMail.Subject)
For Each M In M1
' M.SubMatches(1) is the (\w*) in the pattern
' use M.SubMatches(2) for the second one if you have two (\w*)
Debug.Print M.SubMatches(0)
StrName = StrConv(M.SubMatches(0), vbProperCase)
Next
End If
With olReply
.BodyFormat = 2
.Display
'deletes blank space present before signature
signature = Replace(olReply.HTMLBody, "<p ><o


'removes entire e-mail contents and then closes with discard
olReply.HTMLBody = Replace(olReply.HTMLBody, olReply.HTMLBody, "")
olReply.Close 1
End With
On Error Resume Next
With olReply
.HTMLBody = "Ciao " & StrName & "," & "<br><br>" & "dati contabili creati. " & "<br><br><br>" & "Cordiali saluti" & signature ' & .HTMLBody
.Display 'or use .Send
End With
On Error GoTo 0
Else:
With olReply
.BodyFormat = 2
.Display
'deletes blank space present before signature
signature = Replace(olReply.HTMLBody, "<p ><o


'removes entire e-mail contents and then closes with discard
olReply.HTMLBody = Replace(olReply.HTMLBody, olReply.HTMLBody, "")
olReply.Close 1
End With
On Error Resume Next
With olReply
.HTMLBody = "Ciao " & StrName & "," & "<br><br>" & "dati contabili creati. " & "<br><br><br>" & "Cordiali saluti" & signature ' & .HTMLBody
.Display 'or use .Send
End With
On Error GoTo 0
End If
Next olMail
Set olReply = Nothing
Set olMail = Nothing
End Sub
Thanks for Help me
Gianni