Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding Hyperlinks to a Table Crashes Word (Word 2002 SP1)

    I have a template that copies data from a local HTML file into a new file, creates headings and then creates a table at the top of the new document with hyperlinks to the various Headings within the document.

    The code I am using, at the bottom of the post, works perfectly using W2K, but when run in W2K2 it will fill the first column just fine, but as soon as it starts to fill the second column with the hyperlinks Word Freezes and then eventually crashes.

    I have spent all day searching the MSKB, Google and the Usenet for anything that even remotely similar. Does anyone have any idea of this is a bug in W2K2? Or is my code wrong?

    Thanks for any insight.

    <pre><font color=448800>' Get Rows and Columns for Link table at the top</font color=448800>
    intCount = docMe.Bookmarks.Count
    intMaxCol = 4

    <font color=448800>' Figure out the number of rows needed</font color=448800>
    If intCount Mod intMaxCol = 0 Then
    intMaxRow = intCount / intMaxCol
    Else
    intMaxRow = Int(intCount / intMaxCol) + 1
    End If

    <font color=448800>' Create Table</font color=448800>
    Set rng = docMe.Range(docMe.Content.Start, docMe.Content.Start)
    Set tbl = docMe.Tables.Add(rng, intMaxRow, intMaxCol, , wdAutoFitContent)

    <font color=448800>' Remove Table Borders</font color=448800>
    tbl.Borders.InsideLineStyle = wdLineStyleNone
    tbl.Borders.OutsideLineStyle = wdLineStyleNone

    <font color=448800>' Set starting values of Row and Column</font color=448800>
    intRow = 1
    intColumn = 1


    For Each par In docMe.Paragraphs
    <font color=448800>' Is the paragraph an H3</font color=448800>
    If par.Style = "Heading 3" Then
    <font color=448800>' Set Name for Hyperlink</font color=448800>
    strHLink = Left$(par.Range.Text, Len(par.Range.Text) - 1)
    <font color=448800>' Loop through State Names to get the right one</font color=448800>
    For intLoop = 0 To UBound(aryStates())
    If aryStates(intLoop, 0) = strHLink Then
    <font color=448800>' Add a Hyperlink in the table to the State Name</font color=448800>
    <font color=448800>' docMe.Hyperlinks.Add tbl.Cell(intRow, intColumn).Range, , _
    aryStates(intLoop, 1), , strHLink</font color=448800>
    <font color=448800>'The line above was the original line that freezes Word
    'I changed it to the line below and it still freezes here</font color=448800>

    docMe.Hyperlinks.Add Anchor:=tbl.Cell(intRow, intColumn).Range, _
    SubAddress:=aryStates(intLoop, 1), TextToDisplay:=strHLink
    Exit For
    End If
    Next
    <font color=448800>' Increment Rows and Columns for Down and then over</font color=448800>
    If intRow = intMaxRow Then
    intRow = 1
    intColumn = intColumn + 1
    Else
    intRow = intRow + 1
    End If
    End If
    Next</pre>


    Any ideas? Any suggestions?

    This is being run on WinXPP SP1

    Thanks
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Hyperlinks to a Table Crashes Word (Word 2002 SP1)

    hi Bryan,

    i can confirm your results (crashing that is), but i think i've found the solution.
    you need to set a reference to the cell range and then collapse that range before you add the hyperlink :

    dim HLCellRange as range
    '.....
    '.....
    set hlcellrange=tbl.Cell(intRow, intColumn).Range
    hlcellrange.collapse
    docMe.Hyperlinks.Add Anchor:=hlcellrange, _
    SubAddress:=aryStates(intLoop, 1), TextToDisplay:=strHLink

    i believe word might be having problems with the cell marker inside the range...

  3. #3
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Hyperlinks to a Table Crashes Word (Word 2002 SP1)

    pieter,

    That worked beautifully. <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

    Although, I was sure I tried something similar and it still crashed. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

Posting Permissions

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