在主题中搜索字符串 [英] Search for a string in a subject

查看:54
本文介绍了在主题中搜索字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MSOutlook 中使用 VBA 来搜索主题行中的字符串,如果存在则提示警告.

I am using VBA in MSOutlook to search for a string in the subject line and if it is present then prompt a warning.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim strSubject As String
    strSubject = Item.Subject
    If strSubject.Contains("ZAFTM") or Else strSubject.Contains ("BENSP")    Then
        Prompt$ = "operator, Can I send the mail?"
        If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
            Cancel = True
        End If
    End If
End Sub

这给了我一个 strSubject 的无效限定符的错误.

This gives me an error for invalid qualifier for strSubject.

推荐答案

您正在将 VB.net 语法与 VBA 混合使用.VBA 中的字符串不是对象,也没有方法.

You are mixing VB.net syntax with VBA. Strings in VBA are not objects and have no methods.

在 VBA 中使用 Instr()Like

Use Instr() or Like in VBA

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
strSubject = Item.Subject
If strSubject Like "*ZAFTM*" or strSubject Like "*BENSP*" Then

    Prompt$ = "operator, Can I send the mail?"

    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, _
                                           "Check for Subject") = vbNo Then
        Cancel = True
    End If

End If
End Sub

这篇关于在主题中搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆