word 调入宏的问题?

jing2003 2004-12-03 06:43:18
操作系统: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时出错,如何解决?
这个问题困扰了很长时间,得到解决,高分相赠,决不失言
...全文
90 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LOVETINA49 2004-12-10
  • 打赏
  • 举报
回复
你把问题再说的清楚些。帮顶!
jing2003 2004-12-05
  • 打赏
  • 举报
回复
不是,是想在打开word时,用程序把宏调见来。
jing2003 2004-12-05
  • 打赏
  • 举报
回复
得到解决,高分相赠
ducklingcid 2004-12-05
  • 打赏
  • 举报
回复
你是想在WORD中的固定位置写入数据吗?
xiaoslong 2004-12-03
  • 打赏
  • 举报
回复
帮你顶
huleeyar 2004-12-03
  • 打赏
  • 举报
回复
不会,帮顶

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧