Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6201027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:28:40+00:00 2026-05-24T04:28:40+00:00

I have the macro below, everything I read states it should work, but when

  • 0

I have the macro below, everything I read states it should work, but when I go to send an email it returns a “User defined type not defined”, right at the line Dim objRE As New RegExp

However it is defined, not sure why it returns the error. Can anyone help, thank you.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim newMail As Outlook.MailItem
Dim recip As Outlook.Recipient
Dim isExternal As Boolean
Dim Msg As Outlook.MailItem
Dim m As Variant, em As Variant
Dim strBody As String
Dim intIn As Long
Dim intAttachCount As Integer, intStandardAttachCount As Integer
On Error GoTo handleError

'for ssMacro
Dim hforewnd As Long
Dim x As Long
Dim myOlExp As Outlook.Explorer
Dim myOlExps As Outlook.Explorers
Set myOlExps = Application.Explorers
Dim aryStates(1000) As Long

Dim itm As Outlook.MailItem
Dim vResp As Variant

Dim prompt As String


'Edit the following line if you have a signature on your email that includes images or other files. Make intStandardAttachCount equal the number of files in your signature.
intStandardAttachCount = 0

strBody = LCase(Item.Body)

intIn = InStr(1, strBody, "original message")

If intIn = 0 Then intIn = Len(strBody)

intIn = InStr(1, Left(strBody, intIn), "attach")

intAttachCount = Item.Attachments.Count

If intIn > 0 And intAttachCount <= intStandardAttachCount Then
    m = MsgBox("It appears that you mean to send an attachment," & vbCrLf & "but there is no attachment to this message." & vbCrLf & vbCrLf & "Do you still want to send?", vbQuestion + vbYesNo + vbMsgBoxSetForeground)
    If m = vbNo Then Cancel = True
End If

handleError:
If Err.Number <> 0 Then
    MsgBox "Outlook Attachment Reminder Error: " & Err.Description, vbExclamation, "Outlook Attachment Reminder Error"
End If

If IsMail(Item) Then
 Set Msg = Item
Else
 ' skip processing
 Exit Sub
End If

If Item.Class = olMail Then
Set newMail = Item

For Each recip In newMail.Recipients
If UCase(recip.AddressEntry.Type) = "SMTP" Then
isExternal = True
Exit For
End If

Next

If isExternal And Msg.Attachments.Count > intStandardAttachCount Then
 em = MsgBox("You are sending an attachment to an outside email address" & vbCrLf & "Do you want to encrypt this message?" & vbCrLf & vbCrLf & "Click YES to stop sending" & vbCrLf & "If already encrypted or don't need to, click NO to send", vbQuestions + vbYesNo + vbMsgBoxSetForeground)
 If em = vbYes Then Cancel = True
 End If
End If

Set newMail = Nothing
Set recip = Nothing

If ufnCheckRegEx(Item.Subject, prompt) Or ufnCheckRegEx(Item.Body, prompt) Then
    prompt = prompt & vbCrLf & "Are you sure you want to send it?"
    If MsgBox(prompt, vbYesNo + vbQuestion, "Social Security Warning") = vbNo Then
    Cancel = True
    End If
End If
End Sub

Function IsMail(ByVal itm As Object) As Boolean
 IsMail = (TypeName(itm) = "MailItem")
End Function

Function ufnCheckRegEx(ByVal str As String, ByRef RetStr As String) As Boolean
    Dim objRE As New RegExp
    Dim colMatches As MatchCollection
    Dim objMatch As Match

    objRE.Global = True
    objRE.IgnoreCase = True
    objRE.Multiline = True
    Dim lngCount As Long

    objRE.Pattern = "(\b[0-8][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]\b)|(\b[0-8][0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]\b)|(\b[0-8][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\b)"

    If objRE.test(str) = True Then
        Set colMatches = objRE.Execute(str)
        RetStr = "The subject or body may contain the following social security numbers:" & vbCrLf
        For Each objMatch In colMatches
            If lngCount >= 20 Then
                RetStr = RetStr & vbCrLf & "Note: There may be too many to include in this warning."
                Set objRE = Nothing
                ufnCheckRegEx = True
                Exit Function
            End If
            RetStr = RetStr & objMatch.Value & vbCrLf
            lngCount = lngCount + 1

        Next
        ufnCheckRegEx = True
    Else
        ufnCheckRegEx = False
    End If
    Set objRE = Nothing

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:28:41+00:00Added an answer on May 24, 2026 at 4:28 am

    However it is defined

    Or is it?
    objRE is defined, what about RegExp?

    Tools -> References, Microsoft VBScript Regular Expressions 5.5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen this macro defined before but never really knew its purpose. Can
I have a macro that I wrote to just help me with my unit
I have a macro that looks like this: #define coutError if (VERBOSITY_SETTING >= VERBOSITY_ERROR)
I have a macro which refreshes all fields in a document (the equivalent of
I have a chart in a Worksheet in Excel and I have a macro
I have a 'foreach' macro I use frequently in C++ that works for most
I have the following Macro I want to call from within an AutoHotkey script
I have an access macro, that I want to run automatically from a batch
I have a file with a bunch of lines. I have recorded a macro
I have written an Excel VBA macro which imports data from a HTML file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.