VB 定位word书签的问题!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/01 15:58:59
代码如下,jilu.dot模板已经做好书签了,可运行时,提示424错误:要求对象,错误句子是:
If ActiveDocument.Bookmarks.Exists("name") = True Then '查询书签"name"是否存在

Private Sub Command1_Click()
Set MyWord = CreateObject("Word.Application") '创建WORD文档
MyWord.Visible = True
MyWord.Caption = "汽车维修记录表"
Set NewDoc = Nothing
Set NewDoc = MyWord.Documents.Add(Template:=App.Path & "\jilu.dot") '利用jilu.dot模版生成文档

If ActiveDocument.Bookmarks.Exists("name") = True Then '查询书签"name"是否存在
'若存在,则定位到书签"板的厚度h"所在的范围

Set rngCustomer = ActiveDocument.Bookmarks("name").Range
'将label1中的内容插到书签"name"位置

rngCustomer.InsertAfter Label1.Caption
Else
MsgBox "书签不存在,请重新检查程序!"
End If

ActiveDocument.SaveAs "汽车维修记录表

ActiveDocument这个对象不存在:为什么这样调用呢,从VBA例子中抄的吗,在VBA和WORD共享进程,所以有ActiveDocument这个对象。

直接用NEWDOC调用。
If NewDoc.Bookmarks.Exists("name") =.....