VB怎么打开WORD文档

来源:百度知道 编辑:UC知道 时间:2024/06/07 14:06:17
Dim word As Object
Dim documents As Object
set word = CreateObject("word.application")
Set documents = word.documents.Open(App.Path & "\jy\1.doc")
word.Visible = True

打开WORD后,无法关闭WORD 一关闭就显示“此文件正由另一应用程序或用户使用”,如何解决这个问题
SET word=nothing 我加上了,我要是同时打开2个以上的WORD就会出现这个问题。要是打开一个关闭再打开就没问题,但是同时打开2个关闭后打开的那个就不行了。两个按钮调用的是不同的WORD,没有重复调用一个。锁定了,怎么才能施放干净~~无语了

我看你直接用ole控件来打开就可以了

把word文档的只读,隐藏,存档等属性全去掉试试。

关闭前使用代码释放:
set word=nothing
然后看看。

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "C:\1.doc", "", "", 0
End Sub

Dim word As Object
Dim documents As Object
set word = CreateObject("word.application")
Set documents = word.documents.Open(App.Path & "\jy\1.doc")
上一句执行后word把1.doc锁住了,不能重复使用.如果第二次执行时把1.doc改为其他word文档就没问题,只要你的机器性能够好可以打开许多个word文档.(我在VB6.0调试过的)
word.Visible = True

柳少爷
湖北武汉
2008年6月12日