Outlook VBA设置选择语言

时间:2014-02-03 09:08:04

标签: vba outlook-vba

我正在尝试创建一个宏来设置Outlook电子邮件中的选择语言。

我在VBA脚本方面经验不足。

我将我在Word中录制的宏复制到我的Outlook宏表(或项目,或模块,我不确定它是如何命名的)

Sub SelectionEnglish()
    Selection.LanguageID = wdEnglishUS
    Selection.NoProofing = False
    Application.CheckLanguage = True
End Sub

这不起作用,因为Selection对象不可用。但是我看到了另一个问题(我再也找不到了)宏观作者有办法在outlook宏中使用word-editor。

1 个答案:

答案 0 :(得分:7)

  

是的,电子邮件正文中的文字选择 - tjb 21分钟前

尝试此操作(从Outlook VBA运行)在新创建的电子邮件上进行测试和测试。此代码显示了如何使用Selection对象

Sub Sample()
    Dim oMailItm As Object, oInsp As Object, oMailEd As Object
    Dim oWord As Object, rng As Object

    Set oInsp = Application.ActiveInspector

    If oInsp.CurrentItem.Class = olMail Then
        Set oMailItm = oInsp.CurrentItem
        If oInsp.EditorType = olEditorWord Then
            Set oMailEd = oMailItm.GetInspector.WordEditor
            Set oWord = oMailEd.Application

            '~~> Set your selection object here
            Set rng = oWord.Selection

            '~~> This is to check if we are getting the selection object 
            '~~> You may comment this or remove it later.
            MsgBox rng.Text

            With rng
                '
                '~~> Rest of the code
                '
            End With
        End If
    End If

    Set rng = Nothing
    Set oWord = Nothing
    Set oMailEd = Nothing
    Set oMailItm = Nothing
    Set oMailItm = oInsp
End Sub