Dzwebs.Net

撰写电脑技术杂文十余年

引用word活动文档元素

Admin | 2014-3-17 2:57:10 | 被阅次数 | 5130

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  要引用活动的段落、表格、域或其他文档元素,可使用 Selection 属性返回一个 Selection 对象。通过 Selection 对象,可访问选定内容中的所有段落或第一段。

  下列示例将边框应用于选定内容的第一段
  Sub BorderAroundFirstParagraph()
  Selection.Paragraphs(1).Borders.Enable = True
  End Sub

  下列示例将边框应用于选定内容中的每一个段落
  Sub BorderAroundSelection()
  Selection.Paragraphs.Borders.Enable = True
  End Sub

  下列示例将底纹应用于选定内容中第一张表格的首行
  Sub ShadeTableRow()
  Selection.Tables(1).Rows(1).Shading.Texture = wdTexture10Percent
  End Sub

  如果选定的内容不包含表格,将导致出错。可使用 Count (计数)属性判定选定内容中是否包含表格。下列示例将底纹应用于选定内容中第一张表格的首行。
  Sub ShadeTableRow()
      If Selection.Tables.Count >= 1 Then
          Selection.Tables(1).Rows(1).Shading.Texture = wdTexture25Percent
      Else
         MsgBox "Selection doesn't include a table"
      End If
  End Sub

  下列示例将底纹应用于选定内容中每张表格的首行。For Each...Next 循环用于在选定内容的每张表格中循环。
  Sub ShadeAllFirstRowsInTables()
      Dim tblTable As Table
      If Selection.Tables.Count >= 1 Then   '判断选中区域是否存在表格
          For Each tblTable In Selection.Tables  '这是在选中表中循环的标准写法
              tblTable.Rows(1).Shading.Texture = wdTexture30Percent
          Next tblTable
      End If
  End Sub


该杂文来自: Word杂文

上一篇:两个Range对象变量之间的赋值

下一篇:取消word项目符号与编号格式,保留原来的数字

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计