none
Macros run slow on Word 2007

    Question

  • Hi 

    Using: Windows XP & Word 2003 & Word 2007.

    I have a large set of macros that I use to typeset a 4,500 page book (in 100-200 page chapter files) every year and some of these macros are quite large. Under Word 2003 they ran at what I call "normal" speed. Under Word 2007 they run about 4 or 5 times slower. I have created a number of different WinXP installs to test this, both with and without Word 2007, with and without SPs, etc etc. I have found that the problem occurs after Word 2007 has edited a chapter file. So, if I Save As a file from Word 2007 to a Word 2003 file, then open it with Word 2003 on a machine that has never seen Word 2007 the macros STILL run slow!!! Even if I edit the file in Word 2003 and save it, close it, reopen it and finally run the macros.

    My question is this: Is there a way to save the document as a Word 2003 file so that I lose whatever change that 2007 has made that slows the macros? I cannot save as text as there are many tens of styles in use that I really do not have time to reapply.

    The other, better, solution of course would be for Word 2007 to run the macros fast because the authors now all use 2007.

    I realise this is a long question, but I really would be very grateful for any pointers.

    Thank you,

    Jeremy Gugenheim

    Monday, September 13, 2010 7:47 AM

All replies

  • Hi Jeremy

    Unfortunately, without knowing more specifically what these documents contain, and what the macros do, it's almost impossible to make any suggestions...


    Cindy Meister, VSTO/Word MVP
    Monday, September 13, 2010 9:16 AM
    Moderator
  • Word 2007 does have the ability to save a file in Word 97-2003 format.  I have no idea however whether or not that will change the speed at which the macro runs.

    -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "jgugenheim" wrote in message news:4a5d1400-33aa-4a0d-b30e-482f02e76f1b@communitybridge.codeplex.com...

    Hi

    Using: Windows XP & Word 2003 & Word 2007.

    I have a large set of macros that I use to typeset a 4,500 page book (in 100-200 page chapter files) every year and some of these macros are quite large. Under Word 2003 they ran at what I call "normal" speed. Under Word 2007 they run about 4 or 5 times slower. I have created a number of different WinXP installs to test this, both with and without Word 2007, with and without SPs, etc etc. I have found that the problem occurs after Word 2007 has edited a chapter file. So, if I Save As a file from Word 2007 to a Word 2003 file, then open it with Word 2003 on a machine that has never seen Word 2007 the macros STILL run slow!!! Even if I edit the file in Word 2003 and save it, close it, reopen it and finally run the macros.

    My question is this: Is there a way to save the document as a Word 2003 file so that I lose whatever change that 2007 has made that slows the macros? I cannot save as text as there are many tens of styles in use that I really do not have time to reapply.

    The other, better, solution of course would be for Word 2007 to run the macros fast because the authors now all use 2007.

    I realise this is a long question, but I really would be very grateful for any pointers.

    Thank you,

    Jeremy Gugenheim


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Monday, September 13, 2010 9:45 AM
  • Hi - and thanks for your replies.

    The problem seems to me to be that when Word 2007 saves the files in 2003 format it leaves some 2007 "thing" in them which slows down the running of macros even under Word 2003. If there was some tool out there that was able to convert these files to "genuine" 2003 files I could then use Word 2003 to run the macros at the old speed.

    I don't think there is a problem in the macros themselves as they run correctly under either version of Word, only the speed is different - until the files have been touched by Word 2007, then they run slowly in either version of Word.

    Obviously none of this is ideal, running the macros at full speed in Word 2007 would be a better solution!

    Thanks again and any more ideas would be greatly appreciated.

    Jeremy Gugenheim

    Monday, September 13, 2010 1:30 PM
  • Hi Jeremy

    Have you tried opening the documents in Word 2003 then doing a full Save As to that file format? Or to WordProcessingML (Word's XML file format)? Either of those actions could toss out whatever (round-trip?) stuff Word 2007 is putting into the file...

    But, as I said, unless you provide more information about the document, what it contains, and what the macro does, there aren't many suggestions anyone can make...


    Cindy Meister, VSTO/Word MVP
    Monday, September 13, 2010 4:07 PM
    Moderator
  • Hi

    I'm quite happy to post the macros, but they are huge. The Normal.dot file is 860KB. The chapter files are a bit difficult, I doubt if my client would appreciate it. The basic concept of some of the macros that are horribly slow is that they do a "For Each ch In oldDoc.Words" to work their way through every word of a document - which could be 200 pages long. The one that alerted me to the problem runs to some 800 lines of code. Now, I don't expect it to finish that by the time I've released the mouse button, but an hour??? Word 2003 ran them in about 5 minutes.

    The documents contain mostly words, quite a few tables and a very few .WMF diagrams. All the text is styled, and is laid out in a very hierarchical Section/Subsection/Subsubsection/Bodytext fashion. Indeed the specific macro I mention above rattles through checking that the sections & subsections are numbered correctly.

    I should perhaps add that I was an assembler/C/C++ programmer for 25 years, so I have some idea of how to write code. I'm definitely not trying to brag, just indicate a ballpark level of competence.

    I'm ashamed to say that I only tried a Save, not a Save as, so I will try that. So much for 25 years of experience, eh?

    Thank you very much for your reply, I will certainly try the Save As tip.

    Jeremy

    Monday, September 13, 2010 6:37 PM
  • Hi Jeremy

    I'll be looking forward to learning the results of "Save As" :-)

    "Walking" a document, word-by-word would be slow, yes.

    Moving forward to the new file formats it might make sense to look at processing the OpenXML file, rather than automating the Word application. Standard .NET Framework XML and Packaging namespaces can help you lay open the file and work directly with the internal document.xml. That would have to be loads faster in execution than even Word 2003.


    Cindy Meister, VSTO/Word MVP
    Tuesday, September 14, 2010 5:32 AM
    Moderator
  • Hi Cindy,

    Just tried the save as trick in Word 2003 (after Save As in Word 2007) and... No change. Still really slow. There is a possibility that I should use Word 2003 to convert from 2007 - but I found a couple of changes in the output file - one quite important one was that footers had been deleted! This didn't happen using 2007 to do the initial conversion.

    I suspect the XML route is the answer, but the project is running out of time this year so I think I will just have to thrum the desk with my fingers a lot for the next few weeks and then look at it all properly after publication. The only difficulty I can see with the XML method is that, because it would be a standalone program rather than built into Word, I could see my client smelling "magic" and assuming a rat. Also they may feel worried about ongoing support (what if I get run over by a bus etc.).

    I'm a bit disappointed at what MS have done, I have scoured the web for speed info on Word 2010 but have seen no comment. Perhaps I should download the 30 day trial and run some tests.

    Anyway, many many thanks for your input and your time, I have found the MVP site a life saver before and really appreciate all your efforts.

    Jeremy

     

    Tuesday, September 14, 2010 10:09 AM
  • Hi Jeremy

    <<Just tried the save as trick in Word 2003 (after Save As in Word 2007) and... No change. Still really slow. There is a possibility that I should use Word 2003 to convert from 2007 - but I found a couple of changes in the output file - one quite important one was that footers had been deleted! This didn't happen using 2007 to do the initial conversion.>>

    Mmm. That shouldn't happen. Perhaps this document is slightly corrupt? That could be part of the reason for the speed differences?


    Cindy Meister, VSTO/Word MVP
    Tuesday, September 14, 2010 3:29 PM
    Moderator
  • Ah, well, there's the thing. These chapters are many years old and have never been restarted from scratch, always from the previous year's effort. There is a bug known to Microsoft concerning the display (or otherwise) of text condensed by less than 0.2 of a point in some of them and I am quite sure other bits of detritus as well.

    We had sort of hoped that, moving to the new file format, some of these historical problems might go away!! Oh well...

    I'm not convinced about the speed comment though, because if I go back to a chapter that has not been edited by 2007 (last year's chapters) then the macros run at normal speed under 2003.

    I have now tried this under Windows 7 on my Dell and Windows XP in a Parallels VM on my Mac. The results are the same on both systems.

    Jeremy

    Tuesday, September 14, 2010 3:52 PM
  • Hi jgugenheim,

    How is this issue going on in your side? Have you solved the problem?

    Best Regards,
    Amy Li
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, September 20, 2010 1:23 AM
    Moderator
  • Hi,

    I was very interested to find this thread. We too are experiencing a very similar problem. We have a large word document (Office 2003), and process it with a large macro to generate HTML (we also use the word document to create a pdf file) to use as help in our application. When we first generated this on Windows XP it took about 20 minutes to run. Then, for no apparent reason, it suddenly increased the time to 3 hours. There is a team of 4 developers, and on different machines it took either one or the other of those times (consistent for the machine).  All these machines were using exactly the same files checked out of subversion. There was no rhyme or reason as to Office 2003 or 2007 in compatability mode, operating system being XP or Vista, 32 or 64 bit.

    That situation continued for a year or so. Then, about a month ago, my XP machine suddenly decided to revert back to 20 minutes!! Now, I have got a fancy, high performance new Windows 7 machine with Office 2007. And the macro takes - wait for it ..... 10 hours!!!!

    Like the discussions above our macro goes through the whole 350 page document in detail - and yes, we too are C++ programmers with lots of experience (and ability to get it wrong). We have no idea why this should be. An answer would really be welcome.

    Regards,

    Roy

    Friday, October 08, 2010 8:09 AM
  • I've also picked up this thread. I have VBA code that generates text comments in a Word document. The code runs well using Word 2003 but becomes very pedestrian with Word 2007. Paragraphs that appear virtually instantaneously under Word 2003 appear with delays of about 1s between each segment of text. Stepping through the code does not help identify what is causing the problem. I suspect there are some background processes that are getting in the way but I've no idea what they might be. Automatic spelling and grammar checking is turned off by the code so it shouldn't be that. I'm at a loss and VERY frustrated.
    Friday, November 12, 2010 2:15 PM
  • Further to my comments above we have an interesting observation. In all my previous observations we had kept the word document open in full screen mode. However, we have now found that our ten-twelve hours run, on that same new Windows 7 machine, can be reduced to about 1 hour simply by not running in full screen mode and making the window size very small (so that the client window is less than 1 inch square - just enough to see what is happening). This suggests that we need to look at the screen updating.

    Does anyone else see this effect?

    Tuesday, January 04, 2011 12:09 PM
  • *Everybody* sees that effect, in every version of Word -- anything that modifies or
    scrolls the displayed document will slow down macro execution, often by an order of
    magnitude. There are several methods of minimizing the effect besides just making the
    window small:
     
    - If your macro uses the Selection.Find object, replace that with the .Find object of a
    Range variable to avoid scrolling the display. For example, if you have the typical
     
        Selection.HomeKey Unit:=wdStory
        With Selection.Find
              ' set up .Text, .Replacement, etc.
           While .Execute
              ' do some stuff
           Wend
        End With
     
    replace it with
     
        Dim myRg As Range
        Set myRg = ActiveDocument.Range
        With myRg.Find
              ' set up .Text, .Replacement, etc.
           While .Execute
              ' do some stuff
           Wend
        End With
     
    - At the beginning of the macro, set
     
        Application.ScreenUpdating = False
     
    and at the end of the macro set it back to
     
       Application.ScreenUpdating = True
     
    - For extreme cases, try not displaying the Word screen at all
     

    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org
    Tuesday, January 04, 2011 2:47 PM
  • We have a very similar problem - a large text search/manipulation macro runs about 5 times more slowly under 2010. Re. the sudden reversion to the previous speed - this could be due to a conflicting set of macros or add-in that was installed and then deleted. Adobe Acrobat's PDFMaker function, for example, really slows things down (we now use NitroPDF which doesn't have the same problem). I'd never heard of the screen size issue, but it makes sense. I tried it on Word 2003, and a 155 sec run was reduced to 134 secs. I've asked a colleague to try it on his Word 2010. This has been going on since Word 2007, where I seem to recall that the macro execution speed was even worse than 2010. I don't understand why MicroSoft don't come clean on this one, and say what's happening. Or maybe they do, but it's buried somewhere deep in their support documents. John
    Friday, January 28, 2011 12:17 PM
  • I've just come back to this for the next revision of my client's book and the problem is still here on all my machines. The comments about screen updating are doubtless true, but will not be responsible for the delays that are being seen. I have always cut screen updates to a minimum and anyway we are all talking about a sudden change in speed of execution caused by the use of Word 2007.

    My initial feeling was that MS had added a bunch of defensive code to stop macros misbehaving - a wise move. However, this would not explain the reduction in speed on a machine that had never seen an installation of Word 2007. The damage must be in the document file. And it must be damage. Short of hex dumping the documents and looking for differences between a file saved by 2003 and also by 2007 (and then divining what that difference actually means) we are at the mercy of MS who seem to be keeping their heads down.

    I have not tried Word 2010, if anyone has any intel I'd be interested to hear it. If anyone knows of a way of customizing the ribbon on Word 2011 for the Mac then I'll gladly try it there as well -- actually I could download the trial and manually run a macro or two from the developer tab...

    Thanks for all your input, it would be very handy if we could find a solution.

    Jeremy

     

    Tuesday, September 13, 2011 9:46 AM
  • Actually I've just thought of a possible flaw in my last post.

    I cannot remember if the machine that I ran the tests on that had never seen Word 2007 had been updated with all the latest Word 2003 patches. Given that I usually patch everything as soon as possible it is likely that it had been updated. If this was the case then it is possible that after Word 2007 was released, its macro engine was then published for Word 2003. This could explain why the macros run slow under Word 2003 as well now. EXCEPT that I do recall running a macro under Word 2003 at full speed, then running it under Word 2007 slowly ON THE SAME MACHINE and then running it slowly on Word 2003 ON THE SAME MACHINE again - this still indicates there is a change to the document that kicks off different macro behaviour.

     

    Just thought I'd mention it.

     

    Jeremy

    Tuesday, September 13, 2011 10:11 AM
  • This may be a result of crud accumulating in the actual compiled code that Word stores.  If the compilers are different between Word versions, switching may slow things down.

    What has worked for me in similar situations is to export the module to a .bas file, delete the module from the word doc or template where it is stored, and then import the .bas file.

    This seems to clean up crud and speed things up.

    -  Jessica

    Wednesday, October 05, 2011 1:07 PM
  • Hello,

    I am quite familiar withe the problem you describe, although, up to this day, I had not connected it back to a possible corruption of the Word file. It is now clear for me that it is the problem, and, fortunately, there is a solution that is even already installed in Word 2003!

    I am currently using the French version of the program, so please bear with me and interpret my instructions with some flexibility.

    Start Word 2003 and make a standard File - Open dialog. Select the file you want to work with and, instead of pressing the Open button, press on the small downward arrow to the right of it, which will make a drop-down menu appear, with the option "Open and repair". Select it and after a while (depending on the size of your file), you will have a newly scrubbed Word document.

    For my Word files, which I am using to create the web pages of the e-learning web site i-structures.epfl.ch, the original speed of translation under Word 2003 (for a file I just tried, about 80 seconds) is recovered, compared with the 300-some seconds that I got earlier today before I followed through this thread.

    Now, while I am at it, there is an observation I made while I was running my macro. I usually store my files on the University server, so I observed some network traffic while my macro was running (less than 25% for a 100 Mbits network, but nonetheless). I found it strange, and copied my file on my local disk. the Word template with the macros was already on the local disk. So, it should all run locally, no ? Well, with the "old" file, before I repaired it, the network activity was still there, although my macro was only reading and writing to the local disk. I don't know what is going on here, but I would suggest that some process is attempting to do something on the network that it should not be doing. This activity has disappeared after the repair. I should also note that I have a clean machine with an aggressive and up-to-date antivirus on it.

    Hope this helps y'all,

    Ollie

    Thursday, October 13, 2011 2:51 PM
  • Hi Ollie

    I'll try out your suggestion when I get a moment, but I have been through much of this before. See http://www.eggheadcafe.com/community/word/67/10267673/slow-speed-of-vba-macros-written-for-word-2003-in-20072010.aspx

    One thing to note is that Word 2007 onward (which uses compressed/zipped html format files) takes about a second to open a file. If you are searching multiple files, this adds up.

    My experience has been that Word 2007 onwards, using the html format, runs text manipulation macros 8 or 9 times more slowly, and even if you run a null macro it takes 8 or 9 times as long just to open a file in 2007/2010 as in 2003.

    I have several thousand files in our research database, and I can't believe that they are all damaged. If the Open and repair method works, it is probably because Word is doing some rearranging of its own that resolves the problem. We do run the macros in a minimized window, which helps in all versions of Word.

    We tried running Word 2010 with .doc files rather than .docm, and the problem persisted, I suspect because the .doc files had to be converted to an internal html format before Word 2010 could do anything with them.

    If you have any further feedback since your last post, I'd be very interested to hear it.

    Rgds

    John Davidson

    Monday, September 03, 2012 11:26 AM
  • Hi Everyone

    Something that seems to be getting missed (I read the link above with interest) is that once a file has been opened in Word 2007, then saved again as a Word 2003 .doc file, the macros run slow even when the file is opened in Word 2003. You can delete Word 2007 off the system, the macros still run slow. You can copy the file to a PC that has never had Word 2007 installed on it, the macros still run slow. So this can't be an XML problem because the 2003 .doc files use the old binary format.

    Don't they?

    Why can't someone from Microsoft give us an answer?? I have macros that are taking 50 minutes and more to run now that used to run in 5.

    I note it's two days shy of two years since I started this, and we still have no answer... Microsoft - what are you doing???

    Thank you to everyone who has input their tests and suggestions into this thread, it's all deeply appreciated. Maybe one day we'll get there?

    Best

    Jeremy Gugenheim

    Monday, September 10, 2012 8:47 PM
  • Hi John

    <<One thing to note is that Word 2007 onward (which uses compressed/zipped html format files)>>

    Actually, the file format of Word 2007 onwards is a Zip Package of XML files, not HTML. There's a very big difference in how things are processed internally between html and xml.

    Not that this is necessarily relevant to the question at-hand, but it's an important thing to know when discussing Word files...

    Although for many things I think the change in file format could explain why some things process more slowly. Compared to the older binary file format Word probably has to do a lot more processing and juggling to match things up across multiple XML files...


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, September 11, 2012 10:59 AM
    Moderator
  • Hello Again

    Just checking back in again after some time. Did anyone find a resolution to this issue? I now have a superfast 64-bit, i7, 16 GB RAM m/c, but still running Word 2003 because of the slow-running macros issue. But just a few days ago, Word 2003 started running slowly on a database that was largely the same as it always been. Like about 5-10 times as slow, just as before.

    I wonder if there is some conflict between programs, as there is/was with Adobe PDFMaker and other macros (I've necer seen an explanation of that either!), or maybe some of Word's libraries, or something. I'm not using Word 2010, although there is a promotional stub of the thing on my computer, as purchased.

    Watching progress and CPU usage using ProcessExplorer, I noted previously that maximum WINWORD.exe usage was around 12.5%, even when it was running the macros flat out. No doubt, the remainder of the time was spent reading-writing files. But now that things are running slowly, the CPU usage falls to 1.5 to 3%, which explains the fall off in speed. Boosting the priority of Word 2003 makes no difference. But the observation is interesting in that the slow-running-macros issue seems to be down to the amount of CPU resources being allocated to Word 2003. Or could it be that it is suddenly taking ages to open a file? Tests done with Word 2010 awhile back demonstrated that it was taking about 1 sec to open a file and run a null macro, which is significant when you have over a 1000 files.

    Ho hum -- anyone got any bright ideas?

    John

    Monday, December 10, 2012 9:47 AM
  • Had a further thought after reading this dialogue:

    http://go4answers.webhost4life.com/Example/word-ins-event-handlers-word-macro-160869.aspx

    ... which notes that Adobe AddIns are notorious for creating event handler conflicts. I wonder whether Word 2007 onwards uses any inbuilt addins that conflict with some ways of using regular VBA macros. I think that the CPU usage observation is also a fruitful line of enquiry.

    John

    Tuesday, December 11, 2012 4:50 AM