How to check subject line and add spaces in it

R

RS

I have the code that checks for spaces in the subject line after a semicolon
and tells the user to check the subject line. How can I have outlook add a
space after each semicolon if its not there. Thanks...

Example of a subject line: test1;test2;test3;
Need it to be test1; test2; test3;

Private Sub Application_ItemSend _
(ByVal Item As Object, Cancel As Boolean)
Dim strMsg As String
Dim res As Long
If Item.Subject Like "*;[a-z]*" Then
Cancel = True
strMsg = "Please make sure there is a space after each semicolon."
MsgBox strMsg, _
vbExclamation + vbSystemModal, "Missing Subject"
Item.Display
End If
End Sub
 
F

F. H. Muffman

RS said:
I have the code that checks for spaces in the subject line after a
semicolon
and tells the user to check the subject line. How can I have outlook add
a
space after each semicolon if its not there. Thanks...

Example of a subject line: test1;test2;test3;
Need it to be test1; test2; test3;

Private Sub Application_ItemSend _
(ByVal Item As Object, Cancel As Boolean)
Dim strMsg As String
Dim res As Long
If Item.Subject Like "*;[a-z]*" Then
Cancel = True
strMsg = "Please make sure there is a space after each semicolon."
MsgBox strMsg, _
vbExclamation + vbSystemModal, "Missing Subject"
Item.Display
End If
End Sub

Try:

Private Sub Application_ItemSend _
(ByVal Item As Object, Cancel As Boolean)
Dim strMsg As String
Dim res As Long
If Item.Subject Like "*;[a-z]*" Then
strMsg = Item.Subject
strFind = ";"
strReplace = "; "
Item.Subject = Replace(strMsg, strFind, strReplace)
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top