• WordBasic commands (Word 97)

    Author
    Topic
    #361250

    I am trying to get the WordBasic command “ToolsReviewRevisions .FindNext, .Wrap = 0” to work in a VBA macro I am attempting to develop, and am failing miserably thus far. Does anyone know of the correct syntax for this command?

    As a spot of background, the reason I am trying to use this instead of the VBA equivalent is that there is a horrible bug in the “Revisions” object in VBA which prevents it accessing revisions within tables.

    regards
    Grant Cartledge

    Viewing 2 reply threads
    Author
    Replies
    • #545661

      I managed to answer my own question with a bit of experimentation. The command…

      WordBasic.ToolsReviewRevisions FindNext:=True, Wrap:=0

      …seems to do the trick

      regards
      Grant Cartledge

    • #545770

      Thank. One day I’ll get a handle on the Word object model. Until then, I’ll see you later.

      regards
      Grant Cartledge

    • #545793

      Although Grant has signed off until further notice grin, I’m still puzzing over this:

      [indent]


      As a spot of background, the reason I am trying to use this instead of the VBA equivalent is that there is a horrible bug in the “Revisions” object in VBA which prevents it accessing revisions within tables.


      [/indent]- which horrible bug is being referred to, and what does

      WordBasic.ToolsReviewRevisions FindNext:=True, Wrap:=0

      do that

      Selection.NextRevision

      doesn’t?
      When I test these, they behave exactly the same.

      There is one shortcoming – which is the same with both of these – when it comes to revisions in tables – both of these commands will not select individual revisions in table cells, but rather will select the entire row that a revision is found in.

      This is a very annoying limitation, but I think it’s related to a built-in limitation in Word’s comparison feature (at least through Word 2000 anway; haven’t tested on Word 2002 where track changes was supposedly revamped) – if you do a Word Compare Documents on documents that feature revisions in tables, you will get entire rows duplicated, with one marked as an insertion and one marked as a revision, even if there was literally just one character changed in one cell.
      This, despite the fact that when using the Track Changes While Editing feature, you can mark individual changes inside cells.

      This definitely seems like a bug in the VBA object model, but based on a quick test at least, the WordBasic command has the same limitation.
      Hmm, perhaps we’ll never get to the bottom of this (unless Grant is checks in on this thread again eyeout).

      Gary

      • #545950

        Gary:
        My backgroud was too obtuse – sorry. The “horrible bug” to which I refer is only tangentially related to my previous post. The bug, and, from my perspective, it is horrible, is the one where if you attempt to read the prperty of a revision using “ActiveDocument.Revisions(n).” and the revision is in a table it returns “Error 5852 Requested Object is Not Available” – ie Word doth barf grand temps. We “discussed” this briefly back in January (see http://www.wopr.com/cgi-bin/w3t/showthread…p;vc=1#Post7557)

        Now in some idle time (doesn’t happen often hence the delays in raising this subject again) I discovered that the WordBasic equivalent commands to the VBA “ActiveDocument.Revisions(n).” [eg ToolsRevisionAuthor$()] were untroubled by tables and I restarted my quest to write a working revisions indexing program.

        The problem that I then encountered was getting the selection point to each revision in the document in turn, hence my initial query and self-found solution. Thanks to my new-found knowledge about Selection.NextRevision I now have two possible approaches. I can either kludge it this way:

        For Each Revision in ActiveDocument.Revisions
        WordBasic.ToolsReviewRevisions FindNext:=True, Wrap:=0
        ****Read Properties using WordBasic
        Next Revision

        or kludge it this way…

        For Each Revision in ActiveDocument.Revisions
        Selection.NextRevision
        ****Read Properties using WordBasic
        Selection.Collapse Direction:=wdCollapseEnd
        Next Revision

        Either way it’s a kludge but, hey, it seems to work. Of course I have now been inundated with work again and it will probably be another nine months before I can pick it up again – ho hum.

        BtW I don’t suppose you know if the “revision in a table” problem has been fixed in Word 2k or XP do you?


        regards and sorry for the meandering post
        Grant Cartledge

        **Edited by bam to include URL tags**

        • #546123

          Grant,

          Thanks for jogging my memory – I’d forgotten about that thread.

          I’m still left with one little question: when I tried both the WordBasic and VBA commands, they select an entire table row rather than individual cells (even if there are say, separate track changes edits in column 1 and column 3).

          And I’ll assume without testing it again, that VBA is going to balk if you try to return a property relating to the nextrevision in that situation.

          But, assume the situation above, where there are separate revisions in col1 and col3. Further, assume that the author property is different for the two different revisions. Now you use WordBasic to select the next revision, and it selects the whole row. If you then try to return the author property using WordBasic, is it going to balk?

          Gary

          • #546128

            Gary:
            In short – Yes. I actually managed to find some time to play and have got a working, if not ideal, solution.

            In situations such as you describe the “WordBasic.ToolsRevisionAuthor$()” returns an empty string and the “WordBasic.ToolsRevisionDate()” returns “-1”.

            However you can error trap using “WordBasic.ToolsRevisionType()” which returns a numeric code depending on the type of revision selected. It returns “4” for a multiple revision within a selection .

            The full program is reproduced below. It is not elegant nor optimised but it works after a fashion (limited testing to date). It indexes the changes in the target document and writes these in a table in a second document stored in the same directory as the first. The size of the indexing matrix and subsequent table is derived from ActiveDocument.Revisions.Count which, if there are a number of revisions in a table, is highly likely to be too big and you’ll have a number of unpopulated rows in the final index table.

            The usual disclaimers apply – no warranty expressed or implied; if it breaks something or erases your disk or makes your dog bite you etc. etc. it’s not my fault.

            Option Explicit
            Sub GenerateIndexOfTrackedChanges()

            ‘Macro scans a document with tracked changes and creates an
            ‘index of those changes in a new document
            ‘Grant Cartledge – 10-Oct-2001

            Dim blnTC_Display As Boolean
            Dim blnTC_Changes As Boolean

            Dim intTC_ShowIns As Integer
            Dim intTC_ShowDel As Integer

            Dim strRevIdx() As String
            Dim strDocWithChanges As String
            Dim strDocOfIdx As String

            Dim lngNumRev As Long
            Dim lngRevCount As Long

            Dim objRev As Revision
            Dim objIdxTable As Table

            ‘**Housekeeping Stuff**

            ‘Turn off screen updating to remove flicker
            Application.ScreenUpdating = False

            ‘Find the name of the current document
            strDocWithChanges = ActiveDocument.FullName

            ‘Store the status of the Track Changes options
            blnTC_Display = ActiveDocument.ShowRevisions
            blnTC_Changes = ActiveDocument.TrackRevisions
            intTC_ShowIns = Options.InsertedTextMark
            intTC_ShowDel = Options.DeletedTextMark

            ‘Set the Track Changes options to desired
            ActiveDocument.ShowRevisions = True
            ActiveDocument.TrackRevisions = False
            Options.InsertedTextMark = wdInsertedTextMarkUnderline
            Options.DeletedTextMark = wdDeletedTextMarkStrikeThrough

            ‘Find number of changes
            lngNumRev = ActiveDocument.Revisions.Count

            ‘Error trap for no revisions
            If lngNumRev = 0 Then
            MsgBox (“There are no revisions in the target document”)

            ‘Reverse housekeeping for premature exit
            ActiveDocument.ShowRevisions = blnTC_Display
            ActiveDocument.TrackRevisions = blnTC_Changes
            Options.InsertedTextMark = intTC_ShowIns
            Options.DeletedTextMark = intTC_ShowDel
            Application.ScreenUpdating = True
            End

            End If

            ‘There are revisions so let’s prepare the index matrix and change index document
            ReDim strRevIdx(4, lngNumRev)
            strDocOfIdx = Left(strDocWithChanges, (Len(strDocWithChanges) – 4)) & “_ChangeIndex.doc”
            Documents.Add.SaveAs FileName:=strDocOfIdx

            ‘Insert the table to be populated with the changes into the new document
            Set objIdxTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
            numrows:=lngNumRev + 1, _
            numcolumns:=5)
            With objIdxTable
            .Cell(1, 1).Range.Text = “Revision Number”
            .Cell(1, 2).Range.Text = “Author”
            .Cell(1, 3).Range.Text = “Date and Time”
            .Cell(1, 4).Range.Text = “Revision Type”
            .Cell(1, 5).Range.Text = “Page Number”
            .Rows(1).Range.Font.Bold = True
            End With

            ‘**Find the changes**

            ‘Ensure we are looking at the right document and are at the top
            Documents(strDocWithChanges).Activate
            Selection.HomeKey unit:=wdStory

            ‘Find the changes and get their properties
            ‘Using WordBasic commands as .Revisions(n). crashes within a table (Word 97)

            lngRevCount = 1

            For Each objRev In ActiveDocument.Revisions

            Selection.NextRevision Wrap:=0 ‘find next revision and don’t wrap at end of document

            strRevIdx(4, lngRevCount) = Str(Selection.Information(wdActiveEndPageNumber))

            Select Case WordBasic.ToolsRevisionType() ‘convert the revision type code to text
            Case Is = 0
            strRevIdx(3, lngRevCount) = “No Revision”

            Case Is = 1
            strRevIdx(3, lngRevCount) = “Insertion”

            Case Is = 2
            strRevIdx(3, lngRevCount) = “Deletion”

            Case Is = 3
            strRevIdx(3, lngRevCount) = “Replacement”

            Case Is = 4
            strRevIdx(3, lngRevCount) = “Multiple Revisions”
            GoTo BypassProblem ‘Will not return valid Date/Time or Author so bypass these

            Case Is = 6 ‘Apparently undocumented
            strRevIdx(3, lngRevCount) = “Picture”

            Case Is = 7 ‘Apparently undocumented
            strRevIdx(3, lngRevCount) = “Para Num Change”

            Case Else
            strRevIdx(3, lngRevCount) = “**ERROR**”
            GoTo BypassProblem ‘Will not return valid Date/Time or Author so bypass these

            End Select

            strRevIdx(1, lngRevCount) = WordBasic.toolsrevisionauthor$() ‘Author

            strRevIdx(2, lngRevCount) = WordBasic.Date$(WordBasic.ToolsRevisionDate()) _
            & ” : ” & _
            WordBasic.Time$(WordBasic.ToolsRevisionDate()) ‘Date & Time

            BypassProblem:

            Selection.Collapse Direction:=wdCollapseEnd
            lngRevCount = lngRevCount + 1

            Next objRev

            ‘**Write the changes to the new document

            ‘Ensure we are in the correct document
            Documents(strDocOfIdx).Activate

            ‘Write the gathered data into the table
            For lngRevCount = 2 To lngNumRev + 1

            With objIdxTable
            .Cell(lngRevCount, 1).Range.Text = lngRevCount – 1
            .Cell(lngRevCount, 2).Range.Text = strRevIdx(1, lngRevCount – 1)
            .Cell(lngRevCount, 3).Range.Text = strRevIdx(2, lngRevCount – 1)
            .Cell(lngRevCount, 4).Range.Text = strRevIdx(3, lngRevCount – 1)
            .Cell(lngRevCount, 5).Range.Text = strRevIdx(4, lngRevCount – 1)
            End With

            Next lngRevCount

            ‘**Reverse Housekeeping

            ‘Save the change index document
            ActiveDocument.Save

            ‘Reset the Track Changes parameters in the scanned document
            Documents(strDocWithChanges).Activate
            ActiveDocument.ShowRevisions = blnTC_Display
            ActiveDocument.TrackRevisions = blnTC_Changes
            Options.InsertedTextMark = intTC_ShowIns
            Options.DeletedTextMark = intTC_ShowDel

            ‘Reactivate the index document
            Documents(strDocOfIdx).Activate

            ‘Turn screen updating back on
            Application.ScreenUpdating = True

            End Sub

    Viewing 2 reply threads
    Reply To: WordBasic commands (Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: