程序采用VB编程实现,需要机器安装有VB应用程序及Microsoft Office组件。打开VB,新建一个VB工程,取名Proc_Word,将启动窗体命名为FrmMain,选择“工程”菜单中的“引用”,在“引用”对话框中选择 “Microsoft Word8.0 Object Library”(这一步很重要,你必须选择这一ActiveX部件,否则代码不能正确运行,顺便说一句,如果安装的是Office2000,那么应该选择“Microsoft Word9.0 Object Library”)。同时在“工程”菜单中“部件”对话框中选择添加“Microsoft Windows common controls -2.5(sp2)”,以便在窗体设计中可以使用微调控件。
Imports Word
‘打开
Dim mWordapp As Word.Application ‘word 应用程序
Dim mobjDoc As Word.Document ’word 文档
Dim fullFileName as string ‘文件路径
mWordapp = CreateObject(”Word.Application”)
mobjDoc = mWordapp.Documents.Add(FullFileName)
‘关闭
Dim missing As Object = System.Reflection.Missing.Value
mWordapp.Application.Quit()
If Not mobjDoc Is Nothing Then
‘垃圾回收
System.Runtime.InteropServices.Marshal.ReleaseComObject(mobjDoc)
mobjDoc = Nothing
End If
If Not mWordapp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(mWordapp)
mWordapp = Nothing
End If
‘真正释放word进程
GC.Collect()
学习更多教程,请浏览: VB.NET入门教程 雄网
dim
wordapp
as
new
word.application
dim
mydoc
as
word.document
wordapp.documents.add()
mydoc
=
wordapp.activedocument
wordapp.visible
=
true
命名空间
interop.word
interop.microsoft.office.core