当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
计算机一级考试辅导:解剖一段录制的宏
发布时间:2010/3/24 14:58:20 来源:城市学习网 编辑:admin

  解剖一段录制的宏
  利用第九章介绍的录制宏的方法录制一段宏,然后打开Visual Basic 器,在工程管理器中选中当前文档的ThisDocument 模块, 即可看到录制的宏。
  Sub Macro2()
  ‘
  ‘ Macro2 Macro
  ‘ 宏在 97-9-5 由 gszheng 录制
  ‘
  Documents.Open FileName:=" 你好.doc",
  ConfirmConversions:=False, ReadOnly:= _
  False, AddToRecentFiles:=False,
  PasswordDocument:="", PasswordTemplate:= _
  "", Revert:=False, WritePasswordDocument:="",
  WritePasswordTemplate:="", _
  Format:=wdOpenFormatAuto
  ‘打开一个名为“你好.doc”的文档,打开文档时有许多参数, 具体有:确认版本转换为假,只读为假,加入最近文件列表为假, 读取密码文档和密码模板为空,恢复文档为假,写入密码文档和密 码模板为空,格式为打开时辨认。
  Windows("文档 4").Activate ‘激活“文档4”窗口
  If Options.CheckGrammarWithSpelling = True Then
  ‘如果拼写和语法检查为真
  ActiveDocument.CheckGrammar
  ‘对活动文档进行语法检查
  Else
  ActiveDocument.CheckSpelling
  ‘否则,对活动文档进行拼写检查
  End If
  ActiveDocument.Hyperlinks.Add
  Anchor:=Selection.Range, Address:= _
  "http:www.tsinghua.edu.cn/index.htm",
  SubAddress:="", ScreenTip:= _
  "一流大学的网页", TextToDisplay:="清华大学网页" ‘ 在当前文档中插入一个超级连接, 地址为: "http:www.tsinghua.edu.cn/index.htm,本文档的位置为空,屏 幕提示为“一流大学的网页”,文本显示为“清华大学网页”。此 部分宏中引用了Range 对象,该对象代表文档中的一个范围。每一 个 Range 对象由一起始和一终止字符位置定义。和文档中书签的使 用方法类似,Visual Basic 使用 Range 对象识别文档的指定部分。 然而,其区别在于 Range 对象只在已定义对象的过程正在运行时, 才存在。
  ‘Range 对象和选定内容相互独立。也就是说,可定义和复制一 个范围而不需改变选定内容。还可在文档中定义多个范围,但每一窗格中只能有一个选定内容。
  Selection.TypeParagraph ‘插入一个空段落
  ActiveDocument.Tables.Add Range:=Selection.Range,
  NumRows:=2, NumColumns:=3,
  DefaultTableBehavior:=wdWord9TableBehavior,
  AutoFitBehavior:= wdAutoFitFixed
  ‘插入一个表格,行为2,列为3,默认的表格格式为Word 9(即是Word 2000 格式),为适应格式,即如果超过一行,会换行。
  Selection.MoveDown Unit:=wdLine, Count:=2 ‘光标向下
  移动两行
  ActiveDocument.Shapes.AddShape ( msoShapeRectangle,
  270#, 72#, 63#, _
  46.8).Select
  ‘在文档中绘一个矩形,270#, 72#, 63#,46.8 代表在文档中的位
  置。
  Selection.ShapeRange.IncrementTop 7.8 ‘把矩形往下
  移动7.8 个单位
  Selection.ShapeRange.IncrementLeft -9# ‘把矩形往左
  移动9 个单位
  With Selection.Sections(1).Headers(1).PageNumbers
  .NumberStyle = wdPageNumberStyleArabic
  .HeadingLevelForChapter = 0
  .IncludeChapterNumber = False
  .ChapterPageSeparator = wdSeparatorHyphen
  .RestartNumberingAtSection = True
  .StartingNumber = 1
  End With
  ‘以代码表示在文档中是插入空页眉
  Selection.Sections(1).Footers(1).PageNumbers.Add
  PageNumberAlignment:= _
  wdAlignPageNumberRight, FirstPage:=True
  ‘在页脚插入页码,开始页码为1
  End Sub
  Sub Macro3()
  ‘
  ‘ Macro3 Macro
  ‘ 宏在 99-11-30 由 gszheng 录制
  ‘
  ActiveDocument.SaveAs FileName:="good.doc",
  FileFormat:=wdFormatDocument, _
  LockComments:=False, Password:="",
  AddToRecentFiles:=True, WritePassword _:="",
  ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
  SaveNativePictureFormat:=False,
  SaveFormsData:=False, S

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15080520号-20
珠峰网 版权所有 All Rights Reserved