Outlook VBA 设置选择语言 [英] Outlook VBA Set language of selection

查看:66
本文介绍了Outlook VBA 设置选择语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm try to create a macro to set the language of the selection in an outlook email.

我在 VBA 脚本方面的经验很少.

I have little experience in VBA scripting.

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

I copied the Macro I recorded in Word into my Macro-Table for Outlook (or project, or module, I'm not sure how it is named)

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

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

This doesn't work because the Selection object is not available. But I saw another question (which I can't find anymore) where the macro author had a way to use the word-editor inside the outlook macro.

推荐答案

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

Yes, a text selection in the email body – tjb 21 mins ago

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

Try this (To be run from Outlook VBA) Tried and tested on a newly created email. This code shows how to work with the Selection Object

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

这篇关于Outlook VBA 设置选择语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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