|
我是初学者,正在看到《VBA从入门到精通》第二版,书中的“程序清单12.3”有一段程序,我运行了这段程序,运行后出现:运行时错误'91':对象变量或with块变量未设置。希望得到高人的帮助。现列出程序如下:
Sub GenerateGlossary()
Dim strSource As String
Dim strDestination As String
Dim strGlossaryName As String
strSource = ActiveWindow.Caption
strGlossaryName = InputBox _
("Enter the name for the glossary document.", _
"Greate Glossary")
If strGlossaryName = " " Then End
Documents.Add
ActiveDocument.SaveAs FileName:=strGlossaryName, _
FileFormat:=wdFormatDocument
strDestination = ActiveWindow.Caption
Windows(strSource).Activate
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Font.Name = "Times New Roman"
Selection.Find.Text = ""
Selection.Find.Execute
Do While Selection.Find.Found
Selection.Copy
Selection.MoveRight Unit:=wdCharacter, _
Count:=1, Extend:=wdMove
Windows(strDestination).Activate
Selection.EndKey Unit:=wdStory
Selection.Paste
Selection.TypeParagraph
Windows(strSource).Activate
Selection.Find.Execute
Loop
Windows(strDestination).Activate
ActiveDocument.Save
ActiveDocument.Close
End Sub
|
|