绑定 Microsoft Word 对象

模块 BindWord 后期绑定 Microsoft Word 对象,调用方法如下:

Dim sProg As String
sProg = “Word”
Dim oWord As Object
Call BindWord(True)

Public Sub BindWord(ByVal bVisible As Boolean)
If Not oWord Is Nothing Then Exit Sub
On Error Resume Next
Set oWord = GetObject(, sProg & “.Application”)
If Err.Number <> 0 Then ‘没有打开
Err.Clear
Set oWord = CreateObject(sProg & “.application”)
If Err.Number <> 0 Then ‘没有正确安装
Err.Clear
Exit Sub
End If
oWord.Visible = bVisible
End If
On Error GoTo 0
End Sub

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注