foreach - VBA for each loop locked when I revert revisions -


i want both revised , original text document. way:

set wrddoc = wrdapp.documents.open(filename)  each sent in wrddoc.sentences      if sent.revisions.count >=0         after=sent.text         sent.revisions.rejectall          before=sent.text         saverev(before,after)     end if  next 

now fine, except malformed sentences like

this 1 sentence.this another.

will parsed in weird way. first, there one: "this 1 sentence.", 1 both "this 1 sentence.this another."

what happens when there revisions there? first iteration revert revisions on first sentence, second iteration not 'see' revised portion.

bottom line is, first iteration both versions of first sentence, , second iteration original version of first sentence (while getting both versions second sentence).

let me clarify:

let's had original

we started sentence.and sentence.

and revised

we ended sentence.and other sentence.

first iteration result in

before: started sentence.

after: ended sentence.

but second iteration have

before: ended sentence.and sentence.

after: ended sentence.and other sentence.

well, did alter logic, undoing revision reversion:

set wrddoc = wrdapp.documents.open(filename)  each sent in wrddoc.sentences      if sent.revisions.count >=0         wrddoc.undo         after=sent.text         sent.revisions.rejectall          before=sent.text         saverev(before,after)     end if  next 

i because end unaltered document (except last sentence).

the thing is, doing puts macro in infinite loop @ 1 specific sentence.

i have no idea of mechanics of each, have no clue causing hang. altering collection messing loop, don't understand why.

i loop i=0 wrddoc.sentences.count, think make me skip sentences same reasons i'm repeating 1 now, , cannot risk (even if test ok, have sure never happen).

so question (are):

  1. can 1 me figuring out why it's locking on sentence,
  2. is there better way of doing this?
  3. how can solve while making sure not skip sentences.

thank much!

ps: can provide sample documents, let me know if it's needed (maybe i'm doing wrong clear someone, , i'd have make samples cannot share documents i'm working on).

--edit--

ok it's hanging, on 32nd file.

it doesn't hang on sentence, few @ start of document, goes beginning.

i encountered same error, looped in single sentence, , didn't go beginning. think it's same issue. i'll try reproduce original , revised versions here.

originalversion

main title  measurement of variable  1   required tools  1.1 special tools  note:  note procedure (unaltered revision)  equipment name (carrier returned line) (english) assemply equipment pn kit  equipment name (carrier returned line) (english) assemply (another) equipment pn kit  document continues... 

there 2 equipment entries before restarts loop.

revision consisted of inserting document number, first letter of word caps, , changing order between equipment pn , "kit".

revised version

ducument number main title  measurement of variable  1   required tools  1.1 special tools  note:  note procedure (unaltered revision)  equipment name (carrier returned line) (english) assemply kit equipment pn   equipment name (carrier returned line) (english) assemply kit (another) equipment pn   document continues... 

recorded original/revison pairs were:

original..................................revised

{empty}...................................document number

measurement of variable..............measurement of variable

special tools............................special tools

(english) assemply with..................(english) assemply kit

(english) assemply with..................(english) assemply kit

then starts again, recording same entries until break. don't see sentences overlapping talked about, there line break insertion on revision.

thanks!

enumerable objects should not altered during enumeration or bad things can happen (what depends on type of collection).

my guess revision/undo process, combined wonky sentence, causing sentences enumerable change.

you should prepare own collection first, see if makes difference. try set sents = new collection: each sent in wrddoc.sentences: sents.add sent: next use sents main each loop.