word 调入宏的问题?
操作系统:win2000,word2000
代码如下:
Word.ApplicationClass wordApp;
VBIDE.VBComponent newModule;
wordApp = new Word.ApplicationClass();
wordApp.Visible = true;
string SelectFilename="c:\\a.doc";
object filenameOpen=SelectFilename;
Word.Document oDoc;
object oMissing = Missing.Value;
oDoc = wordApp.Documents.Open(ref filenameOpen,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing);
newModule=oDoc.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule);
string sCode =
"sub VBAMacro()\r\n" +
" msgbox \"VBA Macro called\"\r\n" +
"end sub";
newModule.CodeModule.AddFromString(sCode);
newModule.Name="test";
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oDoc);
oDoc = null;
wordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
System.Runtime.InteropServices.Marshal.ReleaseComObject (wordApp);
wordApp = null;
程序在关闭word时出错,如何解决?
这个问题困扰了很长时间,得到解决,高分相赠,决不失言