Word macro to allow the user to edit two displayed documents in the middle of complex
Hello Everyone!
My first thread..and the first thing I learnt is that my Title is way too long!
This is the full title: "Word macro to allow the user to edit two displayed documents in the middle of complex nested Range.Find loops, and continue when finished editing."
OK, so I have a complex macro that compares similar texts having identical reference prefixes in two documents.
The Working document (A) is searched for a particular style, then the reference prefix is extracted.
The prefix is then used to search through the entire other document (B) for a matching reference.
If found, both documents are displayed side-by-side with the two groups of paragraphs, that are associated with the reference prefix, selected.
The user is asked if they want to copy the entire group from doc A to B, or B to A, or edit either doc.
So to allow the user to edit the docs numerous times in the middle of that process, and then resume, working through the entire doc A, is my need.
I have done a lot of searching and so far found using a nonmodal form with a DoEvents loop until the form is unloaded by clicking a button on the form works, but the CPU get "hammered" during the loop.
Does anyone know of a better way?
Best regards,
PeterT
1 Attachment(s)
DoEvents loop hammering the CPU
Thank you Paul.
OK, I've attached everything in the PeterT.zip attachment:
My code in a .bas text file (saved using the Export function of the VBE),
The UserForm files (saved using the Export function of the VBE),
And copies of two documents to be compared.
Explanations:
I suggest you first have a quick look at the code. The DoEvents loop is about 75% down in the code, surrounded by long lines of hashes. If all that I've supplied is way too much to work with, then please let me know. I can provide some simpler example code to demonstrate my "Y" problem, but maybe there is a "Z" solution! - like you've suggested Paul. As I've tried to summarize in my original post, my "X" goal is to allow the user to edit the documents at the point of where the DoEvents loop is currently located. Once editing is complete, the idea is to have the user indicate to the macro that it should continue working through the nested search loops.
And in the hope of being clear about my "Y" problem: When the DoEvents loop is running, which allows the user to edit the documents, even when the user does nothing the CPU load is very high. I'm wondering if:
1. There is a way of reducing the load on the CPU during the loop?
2. There is an easier way of indicating to the macro that the user has finished editing (and is ready to proceed working through the Main document) without using a Form?
For the benefit of others who might want to play with the code, the top "Const WrkgFldr As String = " will need to be changed to point to your folder containing the supplied doc's. I think I have supplied all of the code that will allow it to run...
I'm using Word 365 64-bit (Current Channel) on Windows 10.
I have the UserForm and the code stored in the Word Normal.dotm project, not in any of the documents to be compared.
Please don't hesitate to ask any questions if something isn't clear.
Best Regards,
PeterT