我有一个在打开 word 文档时执行的宏。问题是空词对象(没有文件/文档)在打开文件/文档时打开宏工作正常。如果新的 word 文档打开了文件/文档,则宏不起作用并显示错误消息。
我的宏:Module1 -> normal.dot
Dim varData As Variant
Dim font_type() As String
Dim text As String
Dim font_name As Variant
varData = Array("?", "[[", "\tag", "$", "()", "|", "\label", "\ce", "insert_eq")
For Each font_name In varData
Selection.HomeKey Unit:=wdStory
Call ClearFindSettings
Selection.Find.text = font_name
If Selection.Find.Execute = True Then
Selection.HomeKey Unit:=wdStory
'Selection.TypeParagraph
Selection.MoveUp
alert_msg = "The '" & font_name & "' Text Present in doc"
alert_msg_grp = alert_msg_grp & vbNewLine & alert_msg
End If
Next
Call Error_alert(alert_msg_grp)
End Sub
这个文件。
Private Sub Document_Open()
Call AutoExec
End Sub
Private Sub Document_New()
Call AutoExec
End Sub
错误消息:
Runtime Error '91'
Selection.HomeKey Unit:=wdStory
有人可以帮忙解决这个问题。