|
|
|
|
|
|
Frontpage
|
Add Table of Contents
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000
|
Submitted by:
|
Brandtrock
|
Description:
|
Creates a table of contents for a web page based upon the h1 and h2 tags in the html code.
|
Discussion:
|
Automatically inserts a Table of Contents at the top of a lengthy web page to take users to the various sections on the page by hyperlink.
|
Code:
|
instructions for use
|
Option Explicit
Dim FpVM As FpPageViewMode
Dim objBody As FPHTMLBody
Dim objUL As FPHTMLUListElement
Dim objHdEl As FPHTMLHeaderElement
Dim strUL As String
Dim strTemp As String
Dim i As Integer
Const DQ As String = """"
Sub TOC()
FpVM = ActivePageWindow.ViewMode
ActivePageWindow.ViewMode = fpPageViewNormal
Set objBody = ActiveDocument.body
For Each objUL In objBody.all.tags("ul")
If objUL.Id = "TOC" Then
Exit For
Else
Set objUL = Nothing
End If
Next objUL
strUL = "<ul id=" & DQ & "TOC" & DQ & ">"
For Each objHdEl In objBody.all.tags("h2")
i = i + 1
If Not objHdEl.all.tags("a").Item(0) Is Nothing Then
objHdEl.all.tags("a").Item(0).outerHTML = ""
End If
strTemp = objHdEl.innerHTML
objHdEl.innerHTML = "<a name=" & DQ & "id" & i & DQ & "></a>" & strTemp
strUL = strUL & vbCrLf & " <li><a href=" & DQ & "#id" & i
strUL = strUL & DQ & ">" & strTemp
strUL = strUL & "</a></li>"
Next objHdEl
strUL = strUL & vbCrLf & "</ul>" & vbCrLf
If objUL Is Nothing Then
On Error Resume Next
objBody.all.tags("h1").Item(0).insertAdjacentHTML "afterEnd", vbCrLf & strUL
Else
objUL.outerHTML = strUL
End If
ActivePageWindow.ViewMode = FpVM
End Sub
|
How to use:
|
- With FrontPage running, open the Visual Basic Editor (VBE) by pressing Alt+F11.
- Add a module under Insert>Module from the VBE menu bar.
- Copy the code from above and paste it into the module.
- Run the macro from the FrontPage tools menu: Tools>Macro>Macros (Alt+F8).
- Select TOC from the list of macros.
- Press Run.
- Save the web.
|
Test the code:
|
- To test the code, run it from the tools menu in FrontPage.
- Tools>Macro>Macros (Alt+F8).
- Select TOC from the list of macros.
- Press Run.
- Save the web.
- If no header tags (h1 or h2) exist, the code will do nothing.
- The example file contains identical pages with and without tags for testing the code. Running it from the page with tags results in a TOC being created; running from the page without tags results in nothing being changed.
|
Sample File:
|
Frontpage TOC.zip 1.78KB
|
Approved by mdmackillop
|
This entry has been viewed 85 times.
|
|