VB程序中调用word

来源:百度知道 编辑:UC知道 时间:2024/09/24 08:31:09
vb中调用word的例程序
谁有,能否给我发一个,我给分。ccy@sina.com

Option Explicit
Dim ap As Word.Application, s As String, doc As Document

Private Sub Command1_Click()
Set ap = CreateObject("word.application")
Set doc = ap.Documents.Open("d:\1.doc")
s = doc.Content.Text
Print s
End Sub

Private Sub Form_Unload(Cancel As Integer)
doc.Close
ap.Quit
Set doc = Nothing
Set ap = Nothing
End Sub

上面的肯定不行。打开肯定是乱码。得引用Word库用里面的打开代码才可以。我已经给你发了一个过去了,请查收。我的邮箱sdjn-yty@163.com.
用到了如下代码。请创建一个d:\1.doc文件,以便程序正常运行。
我的空间上有几个宏的实例,你可以参考。地址:http://hi.baidu.com/arteriosclerosis/blog/category/%BA%EA
=================

Option Explicit
Dim ap As Word.Application, s As String, doc As Document

Private Sub Command1_Click()
Set ap = CreateObject("word.application")
Set doc = ap.Documents.Open("d: