我试图将这些VBA代码从Outlook AddIn转换为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
}例外是:
“System.Runtime.InteropServices.COMException”类型的异常发生在OutlookAddInTest.dll中,但未在用户代码中处理 附加信息:此对象模型命令在电子邮件中不可用.
我是C#和的新手,有什么建议吗?
发布于 2015-05-20 12:41:41
感谢尤金·阿斯塔菲耶夫的帮助。方括号起了作用
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 SubC#
private void Inspector_Activate()
{
Document wdDoc = objInspector.WordEditor;
wdDoc.Windows[1].Panes[1].View.Zoom.Percentage = 150;
}发布于 2015-05-18 16:24:28
使用word.Windows.Item(1).View.Zoom.Percentage = 150 ( word来自Inspector.WordEditor)
发布于 2015-05-18 16:27:33
word.Application.ActiveDocument.ActiveWindow.View.Zoom.Percentage = 150;
究竟是什么属性触发了异常?
无论如何,不需要在代码中调用应用程序和ActiveDocument属性。检查器类的WordEditor属性返回文档类的实例(不是Word应用程序实例)。
https://stackoverflow.com/questions/30307141
复制相似问题