Page 2 of 6 FirstFirst 1234 ... LastLast
Results 16 to 30 of 88
  1. #16
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    243
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Hi Paul and Andrew

    Thank you very much for your inputs. I really appreciate your continued generosity.

    Paul, I substituted your suggested code change, but it still failed unfortunately, so I followed Andrew's suggestion and stepped through the macro with F8 and was very surprised that the value for .AttachedTemplate in the code below:

    If .AttachedTemplate.Path = OldPath Then
    .AttachedTemplate = NewPath & "\" & .AttachedTemplate.Name

    was Normal.dotm, instead of the template that is actually attached to the Word 2003 document the macro found. As I am using Word 2010 to run this macro and all of the documents I hope to replace the template in are Word 2003, which does not use .dotm, I guess it is picking up the attached template to the blank Word 2010 document that I am running the UpdateServer macro from.

    This I suppose is the reason it has never worked.

    What am I doing wrong?

    Regards
    useful

  2. #17
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts
    Hi useful,

    The code is specifically telling Word to find the template attached to the document it has just opened, not to template attached to the document running the code, so I don't understand how Normal.dotm could possibly be referenced. What do you see if you insert:
    MsgBox .AttachedTemplate.Fullname
    before:
    If .AttachedTemplate.Path = OldPath Then
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #18
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    243
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Hi Paul

    I inserted the code you sent and can confirm that it is definitely picking up the template attached to the document where it is running from - in other words the Normal.dotm (it displays the full path \AppData\Roaming\Microsoft\Templates\Normal.dotm), rather than the document it has just opened.

    It makes no sense to me either, but I don't know how to modify the code to fix it. Clearly this is why it failed consistently during my previous testing.

    Regards
    useful

  4. #19
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts
    Hi useful,

    Try deleting: ', Visible:=False', while retaining 'MsgBox .AttachedTemplate.Fullname'.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #20
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    243
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Hi Paul

    I have deleted 'Visible = False', but it made no difference. The Message Box still displays the local Normal.dotm, with the full path \AppData\Roaming\Microsoft\Templates\Normal.dotm, rather than the document that has just been opened.

    Regards
    useful

  6. #21
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts
    Are you sure that the opened document's template path isn't (hasn't been changed to) that path & template?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #22
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    243
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Hi Paul

    I am very confused.

    I have opened the test document and get the 'Contacting \\TSB\Vol1\Doc\Gen\Word2002' message, then I check using File | Options | Add-ins | Manage Templates and get the template path of \\TSB\Vol1\Doc\Gen\Word2002, but when I run your code MsgBox ActiveDocument.AttachedTemplate.Path it shows the path to the local Normal.dotm template, \AppData\Roaming\Microsoft\Templates.

    I then tested a number of Word documents that have not been involved in the testing and I get the same results. All of these files display the 'Contacting \\TSB\Vol1\Doc\Gen\Word2002' message during the opening stage, then eventually time out when they can't find the server. When I look at the attached template in Word (as I set out above) it displays the old Novell path, but when I run your Test code, I get the path to the local Normal.dotm template.

    Regards
    useful (aka George)

  8. #23
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts
    Hi George,

    In post #13, you said:
    I ran your Test macro on the old test Word document and it returned the Template Path as \\TSB\Vol1\Doc\Gen\Word2002. I then confirmed this using File | Options | AddIns | Manage Templates and it was the same.
    Running the larger macro I provided does nothing to change that (before updating to ne new path). Your '\AppData\Roaming\Microsoft\Templates' path and 'Normal.dotm' are never referenced, so I can't see how it's possible to get such results.

    Do you have a couple of (not sensitive - you can delete all the content if you wish) documents referencing the old path that you can attach to a post for me to do some testing with?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #24
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    243
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Hi Paul

    I'm grateful that you will look at the files ... it really makes no sense to me, but perhaps I have done too much testing and I'm just confused.

    There are two documents, as you requested:

    Test1.doc is the test document I have been running the code on;
    Test2.doc is one of the documents from the Novell server that has not been involved in the process.

    Thank you.

    Regards
    George
    Attached Files Attached Files

  10. #25
    3 Star Lounger
    Join Date
    Apr 2012
    Posts
    237
    Thanks
    3
    Thanked 24 Times in 24 Posts
    Except for a very few rare cases, there is absolutely nothing contained in the original template that ever needs to be accessed. I've got a short piece of code here that will run on Open, if inserted into your "Normal" document template, and just deletes the path to the template. This will automatically be replaced with the path to "Normal", no need to check what's already there. Maybe someone can work it into a looping macro, that's a bit beyond my skillset.

    Code:
    Private Sub Document_Open()
    
    ' ClearTemplatePath Macro
    '
    '
        With ActiveDocument
            .UpdateStylesOnOpen = False
            .AttachedTemplate = ""
            .XMLSchemaReferences.AutomaticValidation = True
            .XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
        End With
    End Sub
    Which version of Word are you using? With Word 2010, if you open a template from Windows Explorer, you can't "hurry" the opening process along, but if you open it from within Word, you can press Escape to skip the document search.

  11. #26
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts
    Quote Originally Posted by BigMac56 View Post
    Except for a very few rare cases, there is absolutely nothing contained in the original template that ever needs to be accessed.
    Those "very few rare cases" are a lot more common than you might think. For example, they apply to any document whose template runs a Document_Open macro or an event-driven macro and to any document that has the 'Automatically update document styles' attribute set.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  12. #27
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts
    Hi George,

    What your attachments show is that, aside from the volume names, the paths to the template folders differ, so we'll need to use code that replaces just the changed part of the path.
    Test1 = \\TSB\VOL1\Doc\Gen\Word2002\Coloured Letter_02.dot
    Test2 = \\TSB\VOL1\Doc\Gen\Word97\Coloured Letter.dot

    The question then becomes one of correctly encoding the old & new server names. In my testing, I've confirmed that you can indeed use:
    OldServer = "\\TSB\VOL1"
    Although I can't test it (because Word won't allow me to change to a non-existant attached template path) you should also be able to use:
    NewServer = "\\TSLSERVER\Files"
    or, perhaps:
    NewServer = "H:\Files"

    I've also confirmed that, notwithstanding the dialogue's contents, if an attached template can't be found, code like 'MsgBox ActiveDocument.AttachedTemplate.Fullname' returns only the Normal template - one needs to query the dialogue explicitly for it's interpretation of the attached template.

    What I suggest you do is to open one of the test files on a PC attached to your network and run the following code:
    Code:
    Sub Test()
    Dim OldServer As String, NewServer As String, Dlg As Dialog, Doc As Document, strPath As String
    OldServer = "\\TSB\VOL1": NewServer = "\\TSLSERVER\Files"
    With ActiveDocument
      ' Update the template path
      Set Dlg = Dialogs(wdDialogToolsTemplates)
      strPath = Dlg.Template
      MsgBox .AttachedTemplate.FullName & vbCr & strPath
      If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then
        MsgBox strPath & vbCr & NewServer & Mid(strPath, Len(OldServer) + 1)
        .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
      End If
    End with
    End Sub
    Word will either update the template path or report an error, in which case, try changing the 'NewServer' details. Once you've got it working re-run the full-blown macro with the updated 'NewServer' details in:
    Code:
    Sub UpdateTemplateRefs(strDoc As String)
    Dim OldServer As String, NewServer As String, Dlg As Dialog, Doc As Document, strPath As String
    OldServer = "\\TSB\VOL1": NewServer = "\\TSLSERVER\Files"
    ' Open the document
    Set Doc = Documents.Open(strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto, Visible:=False)
    With Doc
      If .ProtectionType = wdNoProtection Then
        ' Update the template path
        Set Dlg = Dialogs(wdDialogToolsTemplates)
        strPath = Dlg.Template
        If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then
          .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
          ' Update the file counter for changed files
          i = i + 1
        End If
      End If
      ' Update the main file counter
      j = j + 1
      .Close SaveChanges:=True
    End With
    ' Let Word do its housekeeping
    DoEvents
    Set Doc = Nothing: Set Dlg = Nothing
    End Sub
    (the above is a slightly simplified version of the original)
    Last edited by macropod; 2012-11-25 at 22:29. Reason: Code fix
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  13. #28
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    243
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Hi Paul

    Thank you very much for the new codes. You are really great for doing this.

    I opened a document with the Novell path to the template and ran the 'Test' code above, as you suggested, and after I put in the required 'End With' into the code it worked fine! I then replaced the 'UpdateTemplateRefs' section of the original code with the one above and ran it, but it failed.

    It is quite possible that I misunderstood something, otherwise there must be some vital difference between the two code sections.

    I would be very grateful if you could have a look.

    Thank you.

    Regards
    George

  14. #29
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts
    Hi George,

    Did you do a manual check or a re-run the test code against your test document to confirm that the template path had in fact been changed?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  15. #30
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    243
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Hi Paul

    I firstly opened the document to confirm that it displayed the 'Contacting \\TSB\Vol1\Doc\Gen\Word2002' and took over 30 seconds to open.

    I then ran the 'Test' code you so kindly sent and after it ran, I checked the path to the template and it had indeed been correctly modified to the current location, in this case \\TSLSERVER\Files\Doc\Gen\Word2002\Coloured Letter_02.dot

    Then as a further test, I opened the document and it opened straight-away, without the 'Contacting \\TSB\Vol1\Doc\Gen\Word2002' being displayed for about 30 seconds.

    I am wondering though that as we know that the 'OldServer' path no longer exists, if there is any way of eliminating the time for Word to time-out searching for this non-existent path and just replace the path embedded in the file from 'OldServer' to 'NewServer'?

    Thank you very much again.

    Regards
    George

Page 2 of 6 FirstFirst 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •