我在此上下文中收到此错误消息:
int left = 0;
int top = 0;
int width = 0;
int height = 0;
Word.Range rng2 = rng;
Microsoft.Office.Interop.Word.Window.GetPoint(out left, out top, out width, out height, rng);
我该如何解决?
答案 0 :(得分:2)
窗口是非静态的,您需要创建它的新实例才能使用它。
//using Word = Microsoft.Office.Interop.Word;
Word.Application application = this.Application;
//Not sure how you create your application object, just including this incase you're not using VSTO
//Word.Application application =
//(Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
//OR
//Word.Application application = new Word.Application();
Word.Range rng = application.ActiveDocument.Range();
int left,top,width,height = 0;
Word.Range rng2 = rng;
application.ActiveWindow.GetPoint(out left, out top, out width, out height, rng);
或强>
Microsoft.Office.Interop.Word.Window window = application.ActiveWindow;
window.GetPoint(out left, out top, out width, out height, rng);