Accept TC, do somethings, restore TC

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Accept TC, do somethings, restore TC

Post by Robie »

EDIT: Perhaps, this is a better question. Is there a way to know if the parapgraph read has actually been deleted with Tracked Changes *ON*?

Hi

I am travessing a document using vba looking for paragraphs between certain headings. Now, for some documents the track changes is switched-on and there are *deleted* heading paragraphs in between normal text. The vba falls over when it gets deleted tracked changes paragraphs (I don't understand why it actually reads deleted paragraphs).

So, is there a way for me to accept trackedchanges, search between certain headings, extract text to another document and then restore tracked changes? Possibly not but I thought I would just ask.

Thanks.
Robie

User avatar
HansV
Administrator
Posts: 78233
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Accept TC, do somethings, restore TC

Post by HansV »

You can hide markup temporarily using

Code: Select all

    With ActiveWindow.View
        .ShowRevisionsAndComments = False
        .RevisionsView = wdRevisionsViewFinal
    End With
then show them again later using

Code: Select all

    With ActiveWindow.View
        .ShowRevisionsAndComments = True
        .RevisionsView = wdRevisionsViewFinal
    End With
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Accept TC, do somethings, restore TC

Post by Robie »

HansV wrote:You can hide markup temporarily using

Code: Select all

    With ActiveWindow.View
        .ShowRevisionsAndComments = False
        .RevisionsView = wdRevisionsViewFinal
    End With
then show them again later using

Code: Select all

    With ActiveWindow.View
        .ShowRevisionsAndComments = True
        .RevisionsView = wdRevisionsViewFinal
    End With
Thanks Hans but that still doesn't fix it. :-(
It seems I am still getting the deleted paragraphs either using selection or range.

I am now thinking of just taking the content of the activedocument and copying to another document, remove tracked changes, process it and then delete it. Thus keeping the original intact.

User avatar
HansV
Administrator
Posts: 78233
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Accept TC, do somethings, restore TC

Post by HansV »

How do you traverse the document? When I use a loop like this:

Code: Select all

    Dim par As Paragraph
    For Each par In ActiveDocument.Paragraphs
        Debug.Print par.Range.Words(1)
    Next par
I don't get paragraphs marked for deletion if I display "Final"...
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Accept TC, do somethings, restore TC

Post by Robie »

HansV wrote:How do you traverse the document? When I use a loop like this:

Code: Select all

    Dim par As Paragraph
    For Each par In ActiveDocument.Paragraphs
        Debug.Print par.Range.Words(1)
    Next par
I don't get paragraphs marked for deletion if I display "Final"...
That's different. I am expanding a range or selection a paragraph at a time.
Perhaps, I should try your method.

User avatar
StuartR
Administrator
Posts: 12577
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Accept TC, do somethings, restore TC

Post by StuartR »

If you're not making changes to the document in between then you could try

Code: Select all

Sub AcceptRevisionsAndUndo()
    ActiveDocument.AcceptAllRevisions
    ' Do stuff here.
    ActiveDocument.Undo
End Sub
StuartR


Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Accept TC, do somethings, restore TC

Post by Robie »

StuartR wrote:If you're not making changes to the document in between then you could try

Code: Select all

Sub AcceptRevisionsAndUndo()
    ActiveDocument.AcceptAllRevisions
    ' Do stuff here.
    ActiveDocument.Undo
End Sub
Thanks Stuart, that a grand idea.

All I am doing is *reading* from this document - no changes whatsoever. I guess this should work. I will try it out.

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Accept TC, do somethings, restore TC

Post by Robie »

StuartR wrote:If you're not making changes to the document in between then you could try

Code: Select all

Sub AcceptRevisionsAndUndo()
    ActiveDocument.AcceptAllRevisions
    ' Do stuff here.
    ActiveDocument.Undo
End Sub
That was an inspired idea Stuart. It works wonderfully well.

Thank you so much. :clapping: