Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    When is an error not an error? (VBA/Word 2000)

    Hello All,

    I have this little code running below as part of a larger conversion macro that I have built. Basically, my clean-up macro takes a document that has had extensive abuse (i.e., TrackChanges, edited on the Mac, unsafe cutting and pasting practices, etc.) and builds a new document. Old doc is opened, new doc is stared and I go paragraph by paragraph pasting as unformatted text, reapplying styles, direct formatting, rebuilding tables, etc. The code below attempts to separate a merged row at the end of the table (what we call 'table footnote') so that I can reapply formatting more accurately to the rest of the table. This code runs before I paste the table as unformatted text into the new doc. My problem is that even though I have an error handler in this procedure I keep getting a runtime error 5991 for vertically merged cells. I have this error handler because if I can't get a count of the rows in the table, then I can't process the table. Why is my error handler being ignored?

    Public Sub SeperateTableFootnote()
    Dim oRowRange As Range
    Dim oTable As Table
    On Error GoTo ErrorHandler

    For Each oTable In oOldTemplate.Tables
    If oTable.Rows.Count > 1 Then
    If Left(oTable.Rows(oTable.Rows.Count).Range.Text, 3) = "a " Or _
    Left(oTable.Rows(oTable.Rows.Count).Range.Text, 2) = "a" & Chr(9) Or _
    Left(oTable.Rows(oTable.Rows.Count).Range.Text, 7) = "Output:" Or _
    Left(oTable.Rows(oTable.Rows.Count).Range.Text, 8) = "Outputs:" Or _
    Left(oTable.Rows(oTable.Rows.Count).Range.Text, 5) = "NOTE:" Or _
    Left(oTable.Rows(oTable.Rows.Count).Range.Text, 5) = "Note:" Or _
    Left(oTable.Rows(oTable.Rows.Count).Range.Text, 1) = "*" Then
    oTable.Split BeforeRow:=oTable.Rows.Count
    oOldTemplate.UndoClear
    Else
    Set oRowRange = oTable.Rows(oTable.Rows.Count).Range
    oRowRange.Collapse Direction:=wdCollapseStart
    oRowRange.MoveEnd Unit:=wdCharacter, Count:=1
    If oRowRange.Font.Superscript = True Then
    oTable.Split BeforeRow:=oTable.Rows.Count
    oOldTemplate.UndoClear
    End If
    Set oRowRange = Nothing
    End If
    End If
    byebye:
    Next oTable
    Exit Sub
    ErrorHandler:
    If Err.Number = 5991 Then ' Table has vertically merged cells
    Err.Clear
    GoTo byebye
    Else
    MsgBox Err.Number & " " & Err.Description & "." & "Please report to Kyle.", vbCritical
    Err.Clear
    End If
    End Sub

    Thank you,

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: When is an error not an error? (VBA/Word 2000)

    Try changing GoTo byebye to Resume byebye. The Resume command has magic properties that allow you to re-enter the error handler. GoTo does not have these magic properties. Does it work?

  3. #3
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: When is an error not an error? (VBA/Word 2000)

    Yes this worked. Thank you.

Posting Permissions

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