0
votes

I have a word file with approximately 750 fields which link to an Excel file (all to single cells, mostly not the same cell, always the same file), e.g.:

{ LINK Excel.SheetMacroEnabled.12 C:\\Dir1\\Dir1\\ExcelFile.xlsm Daten!Z1S1 \t \* MERGEFORMAT }

Updating the fields (CRTL+A -> F9) right after restarting Word is fairly quick. But if Word wasn't restarted it sometimes takes 10-20 minutes. On some PCs even restarting doesn't help.

When I checked the Task-Manger I saw multiple Excel-Instances could it be the Word open and closes the file for each field, even they all are linked to the same file. Is there a way to force Word to keep the file open?

I played around with the following VBA code with different variations, but so far I had no luck. This is the code I'm trying to get to work (going through all stories) and updating the fields:

Application.ScreenUpdating = False
ThisDocument.StoryRanges(i).Fields.Update
Selection.Fields.Update

I also tried to go through each field individually (which is undesirable since it means I have to build my own progress bar), but it doesn't resolve the performance issue:

Application.ScreenUpdating = False
ThisDocument.StoryRanges(i).Fields(j).Update
Selection.Fields.Update
DoEvents

Is there a way to prevent the low performance, or at least a way to further troubleshoot the problem?

Please Note: I also posted two other questions within this context:

I also posted a second question within this context: stackoverflow.com/questions/57060992Albin
Yes, Word will open Excel and the file for each field and as far as I know there's no way around that - it's just how it was designed to work. I don't know why it would tend to be faster when Word is restarted, except that Word won't be as busy managing the Undo lists. There may also be some internal optimizations involved when Word starts that aren't in effect at a later point, but that's just a guess... Are any of these fields duplicates (same reference)? What kind of data is involved? (Single cells, entire range = Word table, charts...) Do you have Word Automation Services available?Cindy Meister
Thanks for the insight. I feared as much. It's always a single cell (see edit above) but rarely the same. I could Automation Services available, I'll have to check. The work flow is changing the content of the excel file and right afterwards updating the fields in word right after that the word file gets changed some more etc. Will Automation Services be helpful in such a scenario?Albin
Automation Services would only be useful for updating before the file is opened. IOW a scenario where the data may have changed "overnight". But if this is such a dynamic situation... No... However, I do wonder if, for example, it might be faster to connect to the (closed) Excel file using ADO and writing the data to Word. Possibly to a Custom XML Part mapped to content controls (in place of the LINK fields).Cindy Meister
@CindyMeister Yeah, I even would have rather "pushed the data from Excel to Word" in the first place (start the macro from within excel, not word). However for now I'll have to deal with the LINK fields but your suggestion might be a solution for the future. Any other ideas?Albin