+ -
当前位置:首页 → 问答吧 → 请教高手,我写的一段VBA程序可以在WORD2000下插入一个按钮,为什么不能在WORD XP下插

请教高手,我写的一段VBA程序可以在WORD2000下插入一个按钮,为什么不能在WORD XP下插

时间:2004-02-02

来源:互联网

同上.

作者: lovesun   发布时间: 2004-02-02

将你的代码贴上来,让大家看看。

作者: cxffxc   发布时间: 2004-02-02

Private Sub Form_Load()
Dim WdApp As Word.Application
Dim WdTemplate As Word.Template
Dim doc As Word.Document
Dim wdModule As Object
Dim i, Response As Integer
Dim existed As Boolean
Dim Founded As Boolean
Dim lResoult As Long
Dim lKey As Long
Dim strAppPath As String
'Dim strTemplate As String
'判断是否安装了word
lResoult = RegOpenKeyEx(&H80000000, "Word.application", 0, &H1, lKey)
If (lResoult <> 0) Then
'MsgBox ("请先安装Word,再运行本安装程序!")
Unload Me
Close
Exit Sub
End If'判断Word是否已经运行
On Error GoTo errorhandler
Refresh1
Do While True
If WdRunHide Then
Set WdApp = GetObject(, "Word.application")
WdApp.Quit
WdRunHide = False
ElseIf WdRunShow Then
Response = MsgBox("安装程序检测到Microsft Word正在运行,请先关闭Microsoft Word再继续安装Word插件!", 49, "错误提示")
If Response = vbCancel Then
Unload Me
Exit Sub
End If
Refresh1
End If
If (Not WdRunHide) And (Not WdRunShow) Then
Exit Do
End If
Loop
On Error GoTo 0Set WdApp = New Word.Application
WdApp.Visible = False
Set doc = WdApp.Documents.Add
'取模板全名
'On Error GoTo ErrHandle
Err.Clear
On Error Resume Next
Set WdTemplate = WdApp.NormalTemplate
'strTemplate = WdApp.Templates("normal.dot").FullName
If Err.Number <> 0 Then
'strTemplate = "1"
Err.Clear
Set WdTemplate = WdApp.Templates("normal.dot")
If Err.Number <> 0 Then
Err.Clear
Set WdTemplate = WdApp.Templates(1)
End If
End If
On Error GoTo 0
On Error GoTo ErrHandle
'MsgBox WdApp.Templates(1).FullName
'strTemplate = WdApp.Templates("normal.dot").FullName
'检查NewMacros模块是否存在
Founded = False
'For i = 1 To WdApp.Templates(strTemplate).VBProject.VBComponents.Count
For i = 1 To WdTemplate.VBProject.VBComponents.Count
'If WdApp.Templates(strTemplate).VBProject.VBComponents(i).Name = "个人信息中心" Then
If WdTemplate.VBProject.VBComponents(i).Name = "个人信息中心" Then
Founded = True
Exit For
End If
Next i
On Error GoTo 0

作者: lovesun   发布时间: 2004-02-03

逐语句调试看看,看哪里出了问题。

作者: hlrong   发布时间: 2004-02-03

For i = 1 To WdTemplate.VBProject.VBComponents.Count到上面的语句时出错.查看WdTemplate.VBProject.VBComponents.Count值时提示到Visual Basic Project的程序访问不被信任

作者: lovesun   发布时间: 2004-02-04

版主帮忙啊

作者: lovesun   发布时间: 2004-02-04

这里没有版主吗?

作者: lovesun   发布时间: 2004-02-04

帮帮忙啊.

作者: lovesun   发布时间: 2004-02-04

那位大虾帮我解决一下吧,好几天了。

作者: lovesun   发布时间: 2004-02-06

那位VBA达人能不能再完善一下.我想收藏这段代码,谢谢了.

作者: wshcw   发布时间: 2010-11-09