kvitlauk
10-31-2017, 01:24 PM
Hi, all. After figuring out how to create a VBA code to stop sending e-mails with missing attachments, I am now trying to improve my code.
I am actually trying to solve two things:
1) To stop the macro from executing if I am replying to an earlier e-mail that includes buzzwords such as "attachment", "enclosed" etc. I have seen some suggestions with a search function (e.g. searching for the word "From:", which would be the first word to appear in a reply message) , but I just cannot seem to get it right for my code.
2) To stop the VBA from executing if there is a signature with images (which will be counted as attachments by Outlook). I have also seen some suggestions on how to solve this, but the result is the same - it just doesn't work properly
.
Below is my code without indention:
-----
Function SearchForAttachWords(ByVal s As String) As Boolean
Dim v As Variant
For Each v In Array("vedlegg", "vedlagt", "lagt ved", "enclosed", "attached", "Vedlegg", "Vedlagt", "Lagt ved", "Enclosed", "Attached")
If InStr(1, s, v, vbTextCompare) <> 0 Then
SearchForAttachWords = True
Exit Function
End If
Next
End Function
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Attachments.Count > 6 Then Exit Sub
If Not SearchForAttachWords(Item.Subject & ":" & Item.Body) Then Exit Sub
Prompt$ = "Du har glemt å legge ved dokumenter. Vil du fremdeles sende mailen?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Glemt vedlegg?") = vbNo Then
Cancel = True
End If
End Sub
-----
Do you guys have any clue what to do next?
I am actually trying to solve two things:
1) To stop the macro from executing if I am replying to an earlier e-mail that includes buzzwords such as "attachment", "enclosed" etc. I have seen some suggestions with a search function (e.g. searching for the word "From:", which would be the first word to appear in a reply message) , but I just cannot seem to get it right for my code.
2) To stop the VBA from executing if there is a signature with images (which will be counted as attachments by Outlook). I have also seen some suggestions on how to solve this, but the result is the same - it just doesn't work properly
.
Below is my code without indention:
-----
Function SearchForAttachWords(ByVal s As String) As Boolean
Dim v As Variant
For Each v In Array("vedlegg", "vedlagt", "lagt ved", "enclosed", "attached", "Vedlegg", "Vedlagt", "Lagt ved", "Enclosed", "Attached")
If InStr(1, s, v, vbTextCompare) <> 0 Then
SearchForAttachWords = True
Exit Function
End If
Next
End Function
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Attachments.Count > 6 Then Exit Sub
If Not SearchForAttachWords(Item.Subject & ":" & Item.Body) Then Exit Sub
Prompt$ = "Du har glemt å legge ved dokumenter. Vil du fremdeles sende mailen?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Glemt vedlegg?") = vbNo Then
Cancel = True
End If
End Sub
-----
Do you guys have any clue what to do next?