Outlook 加载项 Zoom.Percentage

Outlook AddIn Zoom.Percentage

我正在尝试将此 VBA 代码从 Outlook 加载项转换为 C#

Private Sub objInspector_Activate() Handles objInspector.Activate
        Dim wdDoc As Microsoft.Office.Interop.Word.Document = objInspector.WordEditor
        wdDoc.Windows(1).Panes(1).View.Zoom.Percentage = lngZoom
End Sub

但是我无法访问 Panes.View.Zoom.Percentage 属性

主要思想是当用户打开电子邮件时,他将获得自定义缩放级别。

我目前得到的是:

void Inspector_Activate()          
 {             
// this bool is true
// bool iswordMail = objInspector.IsWordMail();

//I get the word document

Document word = objInspector.WordEditor as Microsoft.Office.Interop.Word.Document;

word.Application.ActiveDocument.ActiveWindow.View.Zoom.Percentage = 150;
// at this point i'm getting an exception
// I've also tried with 
// word.ActiveWindow.ActivePane.View.Zoom.Percentage = 150; getting the same exception                      
}

例外情况是:

An exception of type 'System.Runtime.InteropServices.COMException' occurred in OutlookAddInTest.dll but was not handled in user code

Additional information: This object model command is not available in e-mail.

我是 C# 和 Office 插件方面的新手,有什么建议吗?

使用 word.Windows.Item(1).View.Zoom.Percentage = 150(其中 word 来自 Inspector.WordEditor

word.Application.ActiveDocument.ActiveWindow.View.Zoom.Percentage = 150;

究竟是什么 属性 触发了异常?

反正代码中没必要调用Application和ActiveDocument属性。 WordEditor 属性 Inspector class returns Document class 实例(不是 Word Application 实例)。

感谢 Eugene Astafiev 的帮助。 方括号起到了作用

VBA

Private Sub objInspector_Activate() Handles objInspector.Activate
        Dim wdDoc As Microsoft.Office.Interop.Word.Document = objInspector.WordEditor
        wdDoc.Windows(1).Panes(1).View.Zoom.Percentage = 150
End Sub

C#

private void Inspector_Activate()
        {
            Document wdDoc = objInspector.WordEditor;
            wdDoc.Windows[1].Panes[1].View.Zoom.Percentage = 150;  
        }

我一直想要这个,然后我在 MSDN Gallery 中偶然发现了一个不错的项目 Outlook 2010: Developing an Inspector Wrapper。它有一组适用于所有 Outlook 对象的包装器,因此您可以为每个感兴趣的项目获得一个真实事件。不确定这是否是有史以来最有效的方法,但它似乎有效。

我的视力有问题所以想要黑色的一切,放大一切。我似乎可以通过覆盖 Activate() 方法来做到这一点。这一切都很新,所以我们会看看它是否能长期存在。

    protected virtual void Activate() {
        var activeDocument = Inspector.WordEditor as Document;
        if (activeDocument == null)
            return;

        var mailZoom = GetSetting("MailZoom", 125);
        if (mailZoom != 0)
            activeDocument.Windows[1].View.Zoom.Percentage = mailZoom;

        if (GetSetting("MailBlack", true)) {
            activeDocument.Background.Fill.ForeColor.RGB = 0;
            activeDocument.Background.Fill.Visible = msoTrue;
            activeDocument.Saved = true;
        }
    }

在此示例中,GetSetting 只是一个函数,returns 来自 INI 文件的设置。您可以使用常量或其他一些存储方法。

可能有更好的方法让黑底白字,但这看起来很不错。