问题
I'm try to create a macro to set the language of the selection in an outlook email.
I have little experience in VBA scripting.
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
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.
回答1:
Yes, a text selection in the email body – tjb 21 mins ago
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
来源:https://stackoverflow.com/questions/21523285/outlook-vba-set-language-of-selection