-
How to track changes of a word table using VBA
Hi, I'm finding difficult to track changes done in a table, like cell insertions and deletions ... Here is the code that I have used .... but for some reason it is not recognizing the cell deletion or insertion as a change in the document..... plz help me on this plz.............
[vba]For Each oRevision In oDoc.Revisions
Select Case oRevision.Type
Case wdRevisionInsert, wdRevisionDelete, wdRevisionTableProperty, _
wdRevisionCellDeletion, wdRevisionCellInsertion, wdRevisionCellMerge, _
wdCommentsStory, wdRevisedPropertiesMarkBold, wdRevisionsViewFinal
With oRevision
strText = .Range.Text
Set oRange = .Range
Do While InStr(1, oRange.Text, Chr(2)) > 0
'Find each Chr(2) in strText and replace by appropriate text
i = InStr(1, strText, Chr(2))
If oRange.Footnotes.Count = 1 Then
strText = Replace(Expression:=strText, Find:=Chr(2), _
Replace:="[footnote reference]", Start:=1, Count:=1)
'To keep track of replace, adjust oRange to start after i
oRange.Start = oRange.Start + i
ElseIf oRange.Endnotes.Count = 1 Then
strText = Replace(Expression:=strText, Find:=Chr(2), _
Replace:="[endnote reference]", Start:=1, Count:=1)
'To keep track of replace, adjust oRange to start after i
oRange.Start = oRange.Start + i
End If
Loop
End With
'Add 1 to counter
n = n + 1
'Type of revision
If oRevision.Type = wdRevisionInsert Then
ChangeType = "DataInserted"
ElseIf oRevision.Type = wdRevisionDelete Then
ChangeType = "DataDeleted"
ElseIf oRevision.Type = wdRevisionTableProperty Then
ChangeType = "Table"
ElseIf oRevision.Type = wdRevisionCellDeletion Then
ChangeType = "Table Cell Delete"
ElseIf oRevision.Type = wdRevisionCellInsertion Then
ChangeType = "Table Cell Insert"
ElseIf oRevision.Type = wdRevisionCellMerge Then
ChangeType = "Table Cell Merge"
ElseIf oRevision.Type = wdCommentsStory Then
ChangeType = "Table Cell Insert"
End If
strSQL = _
"INSERT INTO TrackChanges (PageNo,PLineNo, CType, DataChanged, Author, ChangeDate) " _
& "VALUES (" & oRevision.Range.Information(wdActiveEndPageNumber) & "," _
& oRevision.Range.Information(wdFirstCharacterLineNumber) & ",'" & _
ChangeType & "','" & strText & "','" & oRevision.Author & "'," & _
Format(oRevision.Date, "mm-dd-yyyy") & ")"
'Execute the query
'MsgBox strSQL
objCmd.CommandText = strSQL
objCmd.CommandType = adCmdText ' passthrough
objCmd.Execute
End Select
Next oRevision
[/vba]
-
Hi Gane,
Welcome to the board As you are new, you may not be aware that we, like many other forums, discourage cross posting. Most of the members that answer questions work out the "Unanswered Posts" queue. This queue encompasses all forums, so posting your question to multiple forums just results in members seeing the same question three times Also if you enclose the code you post in VBA tags (the little green VBA button) you will notice it will automatically color and indent the code for you, thereby improving readability and speed of response. (I went ahead and added them for you this time.)
As for your question itself, it would be helpful if you could provide example case that is failing to be recorded properly?
Cordially,
Aaron
Keep Our Board Clean! - Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
- Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.
-
When I'm trying to delete a cell from the table in the word document, it could not record it as a change. Even if i remove a table row or column it is not marking as a change. and as a result my code could not identify it .... plz help me in this regard.
-
It is always helpful to mention what version of Word you are using.
Prior to 2007, there is no wdRevisionCellDeletion, wdRevisionCellInsertion, wdRevisionCellMerge, etc. These are not valid Types. They are new to 2007. I wish I could offer a suggestion, but I refuse to use 2007.
-
Can you suggest me how can I do this....if not with word 2007 atleast with word 2003. There should be a way to track the table changes in the word document...and also I'm looking for tracking the changes done to word with respect to images/pictures in it. So plz help me in this regard.
-
Certain things are simply not possible. Deleting a row is not tracked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules