accept edits on doc variables

T

TRM

I am trying to set up code to automatically accept
changes in a document, but only changes to doc variables
on title page of doc) - not changes to the body. Please
forgive my ignorance! I have been able to accept one at
a time, but not move along to each. The code below keeps
giving me errors that the item doesn't exist in this
group (obviously not the exact error). The error comes
on the "... .fields.item(r).type = ... " statement.

THANKS for your suggestions, references & help!

Dim r As Integer
r = ActiveDocument.Revisions.count
Do While r > 0
'keep getting error messages that this does not
exist. Need to find a way to check if
If ActiveDocument.Fields.Item(r).Type =
wdFieldDocVariable Then
ActiveDocument.Fields.Item(r).Select
If (Selection.Range.Revisions.Item(r).Type =
wdRevisionInsert) Or (Selection.Range.Revisions.Item
(r).Type = wdRevisionDelete) Then
'ActiveDocument.Range.Select
Selection.Range.Revisions.Item(r).Accept
'Item(r).Accept
End If
End If
r = r - 1
Loop
'End If
 
D

DA

You're trying to access field items which most probably
aren't there. Why are you using your revision count as
the field index?

Try to cycle through your fields (Up to Fields.Count) and
check the type first.
When you hit a DocVariable field then do your selection
and check on revision.

Hope that helps,
Dennis
 
T

TRM

Thanks - but still having problems. I'm just learning as
I go here! So, sorry if it's taking me a little to "get
it"!

It seems to be getting a little further, but the same
message "requested member of the collection does not
exist".

I was using "revision" to get only the items which had
been revised/changed. I have about the same thing, but
I've made the change you suggested, I think!!

Okay, maybe I can run through this... "r" is a count of
all the fields in the document - "index(r)" indicating
which variable being selected or referred to - (1 - the
first in the doc, etc.) I'm selecting the text/field,
then checking to see if it's an insertion/deletion.
Either way, I want it approved.

That's how my thinking is anyway - like I said, I'm just
learning! Thanks again!

Dim r As Integer
r = ActiveDocument.Fields.count
Do While r > 0
If ActiveDocument.Fields.Item(r).Type =
wdFieldDocVariable Then
ActiveDocument.Fields.Item(r).Select
If (Selection.Range.Revisions.Item(r).Type =
wdRevisionInsert) Or (Selection.Range.Revisions.Item
(r).Type = wdRevisionDelete) Then
Selection.Range.Revisions.Item(r).Accept
End If
End If
r = r - 1
Loop
 
T

TRM

Hey, I think I got it!! However, now I need to check for
a bookmark. I think I can figure that one out (I hope!)

Here is what I have now:

Dim r As Integer
r = ActiveDocument.Fields.count
Do While r > 0
If ActiveDocument.Fields.Item(r).Type =
wdFieldDocVariable Then
ActiveDocument.Fields.Item(r).Select
Selection.Range.Revisions.AcceptAll 'Item(r).Accept
End If
r = r - 1
Loop
 
C

Chad DeMeyer

TRM,

That will work, but consider the following:

Dim oFld as Field
For Each oFld in ActiveDocument.Fields
If oFld.Type = wdFieldDocVariable Then oFld.Range.Revisions.AcceptAll
Next oFld

It is almost always better to use a For Each construct to loop through the
members of a collection. It's faster and makes it easier to understand the
code. It's also almost always better to use a Range object rather than
Selection. In this case, there is definitely no need to select the field
before accepting any revisions within its range.

Hope that helps
Regards,
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top