Search code examples
vbams-wordrevision

VBA Word original text on revised range on readonly files


I am creating a VBA tool to record (for QA purposes) revisions of translated files.

I can read both original and revised text, whitch I do paragraph by paragraph.

But I run into problems every time the file cannot be written to (open by someone else or wasn't closed correctly).

Since the macro will run for a long time, this is an issue. I could work around it, but my client probably will not be able to follow the procedure.

Is there no way to just read the original text without having to modify the file?

It really feels that there should be a way. I serache for a way to copy the range into a dummy and then rever revisions on that new one, but no such luck.

I'm really just doing

set wrdApp=CreateObject("Word.Application")
set wrdDoc=wrdApp.Documents.Open(filePath)

for each par in wrdDoc.Paragraphs
    if par.Range.Revisions.Count <> 0 then
        dim original, revised as String

        revised=par.Range.Text
        par.Range.Revisions.RejectAll
        original=par.Range.Text

        ProcessRevision original, revised
    End if
next

Thanks!


Solution

  • Answering it myself, bottom line is it can't be done. I run into some other issues and had to undo changes after rejecting revisions, but I still can't do it unless I have write permissions.

    My solution to make sure the files were not open somewhere was to copy the files prior to reading.

    It's frustrating that a clearly read operation (getting the original text) need write permission.

    If I ever find another solution, I'll be sure to post here.