Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Mar 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    TOC macro (Word 2003 SP2)

    Hi everyone

    I have created a table of contents macro that looks for styles and builds the TOC accordingly but I need to introduce questions into it as the TOC can be built using either the styles "levels" or "numbering". If it is built using "levels" the user should be given a further choice of including either only level 1 or both level 1 & 2 and finally they need to be asked if the document includes schedules. Based on the answers given the TOC will be built. I am not sure how to do this can anyone shed any light?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: TOC macro (Word 2003 SP2)

    One option is to use message boxes with Yes and No buttons to ask the user questions:

    Sub Test()
    Dim blnLevel As Boolean
    Dim blnLevel1Only As Boolean
    Dim blnSchedules As Boolean
    blnLevel = (MsgBox("Click Yes if you want to use levels." & vbCr & _
    "Or click No if you want to use numbering.", _
    vbYesNo + vbQuestion, "TOC Type") = vbYes)
    If blnLevel = True Then
    blnLevel = (MsgBox("Click Yes if you want to use level 1 only." & vbCr & _
    "Or click No if you want to use levels 1 and 2.", _
    vbYesNo + vbQuestion, "TOC Levels") = vbYes)
    End If
    blnSchedules = (MsgBox("Does the document contain schedules?", _
    vbYesNo + vbQuestion, "Schedules") = vbYes)
    ' You can use the variables blnLevel etc. in your code
    ...
    End Sub

    Another one would be to create a userform in the Visual Basic Editor with check boxes to indicate the user's choices. This is more user-friendly but you need to write more code.

  3. #3
    Lounger
    Join Date
    Mar 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TOC macro (Word 2003 SP2)

    Thanks Hans

    I have gone along the route of creating a userform and have tested this but am unsure how I get this to launch as part of the macro. I cant put it in the document to start when the document is launched as the macro will be part of Normal.dot so I need it to launch only when the macro is activated. Can I do this?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: TOC macro (Word 2003 SP2)

    You can create a macro that will merely show the userform:

    Sub ShowForm()
    UserForm1.Show
    End Sub

    where UserForm1 is the name of the form. You can put the code to create the TOC in the On Click event procedure of a command button on the userform.

  5. #5
    Lounger
    Join Date
    Mar 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TOC macro (Word 2003 SP2)

    Thanks for your help, all now working a treat

Posting Permissions

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