找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 5196|回复: 0

[求助] 请教《VBA从入门到精通》的问题

[复制链接]

1

主题

0

回帖

0

精华

初来乍到

积分
25
发表于 2012-6-16 17:25:03 | 显示全部楼层 |阅读模式
我是初学者,正在看到《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
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表