Consulting

Page 1 of 3 1 2 3 LastLast
Results 1 to 20 of 44

Thread: Format Custom Table of Contents

  1. #1
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location

    Format Custom Table of Contents

    Hi all

    I'm wondering whether that the TOC of Word can be customize to custom setting. Be it by macro or manually...

    The default is
    Heading 1
    Heading 2
    Heading 3

    But I need to customize it to
    Heading 1
    'New Line
    Heading 2
    'New Line
    Heading 3

    Please Help. Thx.

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    If you use the default styles (TOC1, TOC2, TOC3) for headings 1 to 3 you can just modify those styles to reflect your preference (double line spacing)
    K :-)

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Yes, and is a EXCELLENT demostration of the proper use of Styles.

    If we get you right, what you are really wanting (and correct us if we are wrong), is:

    Heading 1
    space between thse lines
    Heading 2
    space between thse lines
    Heading 3


    If this is correct, then I will safely bet that you put in "extra" Enter keys between paragraphs to make the spaces look proper.

    You do not ned this. if the style of the paragraph has that space defined within it...then every instance of that style, will have that space.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Agreed changing the style is the apropriate method.

    Sheeeng, do you no how to do this? (Change a style)
    If not tell us your Word version because the style dialog varies between versions. (So we can tell you how)

    Later.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Yes...it changes a bit between versions, but it all of them it is not that hard. So, sheeng, let us know what version, and we can walk you through changes the styles to get your spaces - if that is what you actually want.

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    The bit between 2000 and 2002 is more of a gap!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    man, you are so fussy.


  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    man, you are so fussy.

    Whahaha....sorry Gerry! (you no I really can't help myself...)
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #9
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    I'm using many versions. 2000, 2002, 2003.

    But primarily is Word 2003. Can anyone customize TOC in VBA macro?

    Possible to do?

  10. #10
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by sheeeng
    I'm using many versions. 2000, 2002, 2003.

    But primarily is Word 2003. Can anyone customize TOC in VBA macro?

    Possible to do?
    Yes its possible but TOC's are bound to styles and if we don't know which styles you're using then it won't be so easy to write you some code...

    This should do what you want:[VBA]
    Sub CustomToc()
    With ActiveDocument
    .Styles("TOC 1").ParagraphFormat.LineSpacingRule = wdLineSpaceDouble
    .Styles("TOC 2").ParagraphFormat.LineSpacingRule = wdLineSpaceDouble
    'Add more modifications
    .TablesOfContents.Add Range:=Selection.Range
    .TablesOfContents(1).TabLeader = wdTabLeaderDots
    .TablesOfContents.Format = wdIndexIndent
    End With
    End Sub
    [/VBA]

    Later
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #11
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    Quote Originally Posted by MOS MASTER
    Yes its possible but TOC's are bound to styles and if we don't know which styles you're using then it won't be so easy to write you some code...

    This should do what you want:[VBA]
    Sub CustomToc()
    With ActiveDocument
    .Styles("TOC 1").ParagraphFormat.LineSpacingRule = wdLineSpaceDouble
    .Styles("TOC 2").ParagraphFormat.LineSpacingRule = wdLineSpaceDouble
    'Add more modifications
    .TablesOfContents.Add Range:=Selection.Range
    .TablesOfContents(1).TabLeader = wdTabLeaderDots
    .TablesOfContents.Format = wdIndexIndent
    End With
    End Sub
    [/VBA]

    Later
    Could I have the links to more information bout this custom TOC macro code?
    This is because i need to customize TOC in different styles...
    Thx.

  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by sheeeng
    Could I have the links to more information bout this custom TOC macro code?
    Links to more information? I have no idea what your talking about.

    To change a style used in the Toc use the name of the style the way I used it.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  13. #13
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    Quote Originally Posted by MOS MASTER
    Links to more information? I have no idea what your talking about.

    To change a style used in the Toc use the name of the style the way I used it.
    Sorry for my poor english...
    What I mean is any internet links to more information on this?
    Thx.

  14. #14
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by sheeeng
    Sorry for my poor english...
    What I mean is any internet links to more information on this?
    Thx.
    Ah Ok..no there's little on this subject to find I think.

    I code it manually so I wouldn't know where resources are. I think you have to search google.

    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  15. #15
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    Quote Originally Posted by MOS MASTER
    Ah Ok..no there's little on this subject to find I think.

    I code it manually so I wouldn't know where resources are. I think you have to search google.

    Thx, Joost.
    You are very helpful.
    Great of having you around..
    Well, I'll wait for others for answers.
    Thx.

  16. #16
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Ok no problem.

    But you should better ask specific problems cause the answers to those are possible.

    There is a lot of documentation available on the Inet but little of it is general purpose. (In VBA little is general purpose)

    The Word object model is difficult so you need to address each specic problem as its own normally.

    So if you have a specific problem I'm there to assist!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  17. #17
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    Quote Originally Posted by MOS MASTER
    Ok no problem.

    But you should better ask specific problems cause the answers to those are possible.

    There is a lot of documentation available on the Inet but little of it is general purpose. (In VBA little is general purpose)

    The Word object model is difficult so you need to address each specic problem as its own normally.

    So if you have a specific problem I'm there to assist!
    Thx

  18. #18
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    sheeeng, hmmmm.....OK, you have to learn some of hpw Word is truly designed.

    Some one could argue, and I am willing to listen, but I will state categorically that Word is designed around styles. It is literally impossible to have a paragraph that is NOT a style. Therefore, to understand Word (or at least some of it), you need to grasp styles. Not just for this exercise, but generally.

    As Joost stated, generated ToC are bound to a style. You may bind a ToC level to any style you wish. Conclusion? Hmmmm, if I want to really control my ToC....I had better design and create my own ToC styles.

    This is where I have to disagree with Joost's post. His code modifies the existing TOC style. I do not think this is, in the long run a proper strategy. This is even more of an issue if you want to be able to have different ToC format or structure.

    Make you own ToC styles; use them in proper templates.

  19. #19
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    This is where I have to disagree with Joost's post. His code modifies the existing TOC style. I do not think this is, in the long run a proper strategy. This is even more of an issue if you want to be able to have different ToC format or structure.
    Hi Gerry,

    As usual we are not in disagreement!

    My post was the exact answer to the original post. (Got no feedback if it worked however..it does here)

    I also said before this shouldn't be done by code but with a proper templates with styles. (Or modify existing TOC styles)

    So...No we agree very much...but Sheeeng wanted a code example so he got one...
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  20. #20
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Some one could argue, and I am willing to listen, but I will state categorically that Word is designed around styles.
    I can't imagine anyone arguing with that.
    K :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •