none
How to avoid accessing template opening docs RRS feed

  • Question

  • I need to know how to skip the initial reading of template when opening a document from VBA
    I have a lot of docs in a network folder referencing to an old template in a location that doesn`t exist anymore and when I try to open them manually it is trying to access the wrong address that doesn`t exist. In the lower bar it indicates to use ESC to abort accessing template and it works and the document opens and I know how to remove the wrong template manually but the problem is that there are too much docs to do it manually one by one, so I thought in a VBA macro but I can`t find the way to avoid the initial access to the template when opening a document and the macro never ends and the computer hangs. Anybody knows how to solve that? Thanks in advance.
    Saturday, June 30, 2012 7:16 PM

Answers

  • The reason I suggested trying subst for the drive is that, even though you were using a server path, Word might still recognize the drive letter that path actually used (ie you use the original drive's letter). I don't know if it'll work, but it's worth a try.

    Really, though, it should be possible to load all the files onto a stand-alone PC, run the macro, then reload the file onto the network. The process could be run after hours to minimize disruption.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, July 11, 2012 2:15 PM

All replies

  • Saturday, June 30, 2012 11:15 PM
  • Sorry about cross-posting if it's a problem for you. I'll continue the thread only in this forum.

    The solution proposed in method 3 at: http://support.microsoft.com/kb/830561 is not valid because it makes the changes only once the files are opened, so it needs to wait the delay caused by wrong template addresses.

    It could work only if you have all the files in a local drive an you disconect the network because the error accesing templates is inmediate. But if the files are in the network you need a way tiosay Word to ignore the template and open the document without it, just the same you get using ESC key manually.

    Anyone knows how to do that?


    Tuesday, July 3, 2012 4:20 PM
  • You cannot change the location where a files looks for its template without opening said file. With many files to process, you may find it quicker to make the change in two steps:

    • disconnet the affected PC from the network or use a stand-alone PC and make the change to a local folder; then
    • reconnet the affected PC to the network or transfer the files to it and make the change to the new network folder.

    You may also get better performance if you set 'Application.DisplayAlerts = False'. As I don't have a network (or mis-directed templates to work with), I can't test it to confirm, though.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, July 3, 2012 9:57 PM
  • Hi mustomat

    In which file format are these documents? If it's the 2007/2010 file format (docx, docm, etc) then you can change the AttachedTemplate attribute without needing to open  the files at all in the Word application. You can leverage the OpenXML file format (best done using a .NET application and the OpenXMLSDK) to change the AttachedTemplate information directly.


    Cindy Meister, VSTO/Word MVP

    Wednesday, July 4, 2012 8:31 AM
    Moderator
  • Thanks Cindy. Good idea, but the majot¡rity of affected files are in old .doc format.

    Wednesday, July 4, 2012 11:49 AM
  • Thanks Paul. I know this works as I mentioned in my last note, but it's not very useful in my case because files are in a shared network folder with a lot of GB in it and I don´t know in advance which are the bad files so I don´t want to copy all this amount of files, then process them locally and copy them back again.

    I supossed that if you can manually stop the reading of the template of a file there should be a way to do a similar thing from a script, but if there isn´t anyth¡ng I'll have to look for another kind of ideas... 

    Wednesday, July 4, 2012 12:01 PM
  • Hi mustomat

    Mmm, the following occurs to me...

    1. You want to know how to emulate the user pressing Esc. The only way I know is "SendKeys", but this is, of course, not reliable. Theoretically, though, you could set up a timer that, after n seconds issues Esc through SendKeys.

    2. Dedicate a machine to the process for a day or so and just wait it out. Once the files have been "cleaned" they won't need to be touched again, so it's not like this is completely "awful", just a pain. And from now on encourage/force people to save to the new file format so that if you run into this again you can fix it using OpenXML.

    3. Invest in software that can directly edit the old file format (or write it yourself, if you're a C++ person). There's a forum here on MSDN about working with those file formats and the file specifications are now in the public domain.


    Cindy Meister, VSTO/Word MVP

    Wednesday, July 4, 2012 3:48 PM
    Moderator
  • Hi again, Cindy.

    I'll try your options 1 and 2. 3 is a bit complex for me.

    I have an aditional doubt about option 2. As the expected time to wait could be very long, is there a way to ensure that the process will end without problems? I say it because the long delays opening files usually causes error messages saying that there are problems in the communication between apps and I'm not very sure if is enough to ignore them and the process will continue or if the PC (or the winword process) will hang forever if it reaches some timeout without having responses.

    Thursday, July 5, 2012 1:00 PM
  • Hi mustomat

    As long as the code doesn't try to execute until the document is available, there shouldn't be any problem I know of. But as a general rule it's always a good idea to have someone monitoring any Office automation. They wouldn't have to sit right in front of the machine, but look in on it every now and then.

    It would probably be a good idea to put some kind of logging into your code, so that you can track which files have been processed successfully. That, or have them saved to a different folder/location.


    Cindy Meister, VSTO/Word MVP

    Thursday, July 5, 2012 1:21 PM
    Moderator
  • With a bit of fiddling around, it might be possible to use the SUBST command when starting Windows on the machine that's doing the macro processing via the code in the link I posted, to temporarily create a dummy drive with the same deignation as the old server. If the dummy drive also has a path that mirrors the path to the old templates foler, with whatever templates are required, you should be able to open the documents quickly, update the template path to where it should now point, then save and close the documents.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, July 5, 2012 9:42 PM
  • Cindy, I've been trying with solutions 1 and 2 but there is no advance.

    I can send keys to a word open document but I don`t know how to send the ESC key to word when it's trying to open a file. If I put the sendkeys command before the open instruction it has no effect, and if it's after the open, its effects are taken only after the file has been opened. I was thinking in sending the ESC from a different function but I don't kmow how to execute it manually or form a script while open instruction is running.

    About the solution 2, I have tried to measure the worst case ot delay opening a file with "bad template" to estimate the  total amount of time needed, but I have found cases where it is waiting more than 15 or 20 minutes withuot receiving any kind of errors, so I think this could be impossible to put a script and wait. I need a way to stop it when some of these files appear. ¿How could I interrupt the open instruction to continue with the next file and leave the bad ones logged for a manual action?

    Sunday, July 8, 2012 4:10 PM
  • Hi mustomat

    IN that case, if you also can't use any of Paul's suggestions, then as far as I know this will have to be a manual process. You can use macros to make it less painful, but you won't be able to automate the entire task.

    You can use a macro to open files one-by-one.

    Someone will have to sit in front of the machine and press ESC when necessary.

    Then that person can click a button or press a keyboard shortcut for a macro that attaches a different template, saves and closes the file.


    Cindy Meister, VSTO/Word MVP

    Monday, July 9, 2012 9:31 AM
    Moderator
  • Thanks again, Cindy. It sounds a bit hard to realize these limitations in automation of microsoft programs, but I supose we have to live with that.

    About Paul's sugestion, I need more information about the "fiddling", because I haven't found this posibility in the description of the SUBST command. 

    Tuesday, July 10, 2012 12:20 PM
  • For basic instructions on the SUBST command, open a command prompt and input:

    SUBST /?

    See also:
    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/subst.mspx?mfr=true


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, July 10, 2012 12:41 PM
  • Thanks, Paul, but these two places are just the same I had read yet, and I can't see there any way to use SUBST in the sense you said: SUBST seems to be designed to assign a letter (as X:) instead of a full path (as \\server\folder\...), but I don't see how to apply it to my case: if Word is trying to access a template in a wrong address as \\server\folder... it would be waiting exactly the same even if I call this X:

    Wednesday, July 11, 2012 12:12 PM
  • The reason I suggested trying subst for the drive is that, even though you were using a server path, Word might still recognize the drive letter that path actually used (ie you use the original drive's letter). I don't know if it'll work, but it's worth a try.

    Really, though, it should be possible to load all the files onto a stand-alone PC, run the macro, then reload the file onto the network. The process could be run after hours to minimize disruption.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, July 11, 2012 2:15 PM