Search code examples
c#vbaoutlookzoomingoutlook-addin

Outlook AddIn Zoom.Percentage


Im trying to translate this VBA code from an Outlook AddIn to 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

But I can't get access to the Panes.View.Zoom.Percentage property

The main idea is that when the user opens an email, he will get a custom zoom level.

What I got at the moment is:

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                      
}

The exception is :

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.

I'm quite new in C# and Office addins, any advise?


Solution

  • Thanks to Eugene Astafiev for his help. The square brackets did the trick

    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;  
            }