使用VBA更改Word目录中的超链接样式 [英] Changing the Styles of Hyperlinks in a table of Contents in Word with VBA

查看:476
本文介绍了使用VBA更改Word目录中的超链接样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在Word文档的目录下遇到超链接样式的问题.在这里,我想更改目录下不同标题级别的每个超链接的样式.但是我无法更改样式它显示默认 样式(蓝色,默认大小等)用于超链接.

I am facing an issue with the Hyperlink styles under Table of contents in a word Document.Here,I want to Change the Styles For Each Hyperlink for different Heading Levels under a table of Contents.But i am unable to change the styles.It is showing the default styles(Blue color,default Size etc) for hyperlinks.

任何人都可以解决我的问题,我需要尽快获得帮助.

Can Anyone Solve my Problem,i need a help ASAP.

预先感谢.

推荐答案

您可以使用TableOfContents获得对每个目录条目的Range对象的引用.Range.Paragraphs属性,并使用该属性直接设置文本的样式:

You can get a reference to the Range object for each table of contents entry using the TableOfContents.Range.Paragraphs property, and use that to set the style of the text directly:

  • Table s OfContents对象:文档中的所有目录
  • TableOfContents对象:单个目录表(包括所有条目)
  • 范围对象:核心MS Word对象模型对象. TableOfContents.Range获取包含以下内容的范围 目录中的所有条目
  • paragraph对象:核心MS Word对象模型对象. TableOfContents.Range.Paragraphs将为每个单独的目录条目返回一个段落对象
  • TablesOfContents object : All the tables of contents in a document
  • TableOfContents object : A single table of contents (which includes all the entries)
  • Range object : Core MS Word object model object. TableOfContents.Range gets the range that includes all entries in the table of contents
  • Paragraph object : Core MS Word object model object. TableOfContents.Range.Paragraphs will return a paragraph object for each individual table of contents entry

一旦获得了对各个条目段落对象的引用,就可以像设置任何其他段落一样设置所有样式和格式设置属性.有关通过VBA应用格式的更多信息,请从以下位置开始 将格式设置应用于文本[Word 2007开发人员参考] .

Once you get the references to the individual entry paragraph objects you can set all the style and formatting attributes as with any other paragraph. For more information about applying formatting with VBA, start at Applying Formatting to Text [Word 2007 Developer Reference].

枚举文档中所有目录中所有条目的示例:

An example of enumerating all the entries in all the tables of contents in a document:


Sub ListTOCEntries()
    Dim tocCollection As TablesOfContents
    Dim tocItem As TableOfContents
    Dim p As Paragraph
    
    Set tocCollection = ThisDocument.TablesOfContents
    For Each tocItem In tocCollection
        For i = 1 To tocItem.Range.Paragraphs.Count
            Set p = tocItem.Range.Paragraphs(i)
            Debug.Print "   Paragraph"; i; "style = "; p.Style
            Debug.Print "   Paragraph"; i; "text = "; p.Range.Text
        Next
    Next
End Sub


这篇关于使用VBA更改Word目录中的超链接样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆