使用块将变量作为参数传递给它自己的参数

时间:2015-02-01 17:29:17

标签: vba reference subroutine with-statement param

我在VBA中调整了我的outlook规则,并且偶然/本能地尝试通过将其作为With块中的点来传递变量

在我的例子中,var是CurrentItem,我的一个子例程在param列表中期望它。通常,您可以通过使用点来简写引用With块内的var(例如,使用regEx .Global = True,.Pattern =&#34; ^。* $&#34; End With)。< / p>

尝试将点作为arg传递却无法正常工作。我很好奇是否有这样的简写在With块中引用var本身?这是代码示例:

With CurrentItem
    If .Class = olMail Then
        sFromName = .SenderName
        sID = .Sender.ID
        ''dot arg that doesn't work:
        ''GetSMTP sFromName, sID, .
        GetSMTP sFromName, sID, CurrentItem 
    End If
End With

1 个答案:

答案 0 :(得分:1)

不,您无法引用With块中的当前项。这确实是你能得到的最好的:

With CurrentItem
    If .Class = olMail Then
        GetSMTP .SenderName, .Sender.ID, CurrentItem 
    End If
End With
相关问题