Page 5 of 6 FirstFirst ... 3456 LastLast
Results 61 to 75 of 88
  1. #61
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,769
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Hi George,

    From what you've posted, I can't see what the cause might be either. That said, you might try changing:
    Code:
          On Error GoTo ErrRpt
          .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
          GoTo OK
    ErrRpt:
        ' Output an error report in the document from which the macro is run.
        ThisDocument.Range.InsertAfter vbCr & "Template: " & NewServer & Mid(strPath, Len(OldServer) + 1) & _
          " not found for " & strDoc
          ' Reset the template to 'Normal'
          .AttachedTemplate = ""
        On Error GoTo 0
    OK:
    to:
    Code:
          strPath = NewServer & Mid(strPath, Len(OldServer) + 1)
          If Dir(strPath) <> "" Then
            .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
          Else
            ' Output an error report in the document from which the macro is run.
            ThisDocument.Range.InsertAfter vbCr & "Template: " & strPath & " not found for " & strDoc
            ' Reset the template to 'Normal'
            .AttachedTemplate = ""
          End If
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    I substituted the code you so kindly sent and ran the macro again and this time it 'crashed' with:

    Run-time error '5180'
    Word cannot open this document template
    (\\TSLSERVER\...\Bill of Costs_02.dot)

    Debug highlighted the line:

    .AttachedTemplate = NewServer & Mid(strPath, Len(oldServer) + 1)

    The template file it says it cannot open is, of course, there so I'm none the wiser as to why it would display that error.

    Regards
    George

  3. #63
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,769
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Hi George,

    Time to check that the template isn't corrupt or protected. Try opening it and/or creating a new file from it.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    I have just opened the template without problems and just created a new file from it, which also worked fine. I have Administrator privileges, so it could not be a rights issue.

    Regards
    George

  5. #65
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,769
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Hi George,

    I just noticed that the file throwing the latest error is a different one than before. Did the previous one end up being processed correctly with the new code? Something else to check is whether the template now throwing the error has any macros or is intended to run a mailmerge.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    The previous file the appeared on the error report and reported that it could not find the template, did process correctly with the new code. All of the templates involved with this process have several macros, but none of the templates are intended to run a mailmerge.

    The very next Word file in the same folder must have tripped up the code when I ran it again, as the template that is attached to that document is the Bill of Costs_02.dot and the code has not updated to the current template path, which still points to the old Novell server path.

    I hope this gives you a suitable clue.

    Regards
    George

  7. #67
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,769
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Hi George,

    In the 'Main' sub, try inserting:
    ' Disable auto macros
    WordBasic.DisableAutoMacros 1
    before:
    Dim StrFolder As String
    and:
    ' Enable auto macros
    WordBasic.DisableAutoMacros 0
    before:
    ' Restore screen updating
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    I inserted the new code in the two places you indicated and ran the macro again on the same person's folder, but it 'crashed' with the same Run-time error '5180' as it did before, with the same message and same Debug highlight.

    Regards
    George

  9. #69
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,769
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Hi George,

    Try it with this version of the 'UpdateTemplateRefs' sub:
    Code:
    Sub UpdateTemplateRefs(strDoc As String)
    ' This sub updates the template paths for files after a server
    ' change. Simply insert however much of the lower end of the
    ' server paths differ as the OldServer and NewServer variables.
    Dim OldServer As String, NewServer As String, strPath As String
    Dim oItem As Object, StrDtTm As String
    OldServer = "\\TSB\VOL1": NewServer = "\\TSLSERVER\Files"
    ' Store the file's current Date/Time stamp.
    If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oItem = FSO.GetFile(strDoc)
    StrDtTm = oItem.DateLastModified
    ' Open the document
    Documents.Open strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto
    With ActiveDocument
      If .ProtectionType = wdNoProtection Then
        ' Update the template path
        strPath = Dialogs(wdDialogToolsTemplates).Template
        If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then
          ' Update the file counter for changed files
          i = i + 1
          ' Get the new template path & name
          strPath = NewServer & Mid(strPath, Len(OldServer) + 1)
          ' Check whether the template exists
          If Dir(strPath) <> "" Then
            On Error GoTo ErrRpt
            ' If found, update the path
            .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
          Else
            ' If not found, reset the template to 'Normal'
            .AttachedTemplate = ""
            ' Output an error report in the document from which the macro is run.
            ThisDocument.Range.InsertAfter vbCr & "Template: " & strPath & " not found for " & strDoc
    ErrRpt:
            If Err.Number = 5180 Then
              ' Output an error report in the document from which the macro is run.
              ThisDocument.Range.InsertAfter vbCr & "Err 5180 - Template: " & strPath & " could not be updated for " _
                & strDoc & ". Please update manually."
            ElseIf Err.Number > 0 Then
              ' Output an error report in the document from which the macro is run.
              ThisDocument.Range.InsertAfter vbCr & "Unspecified error - Template: " & strPath & " could not be updated for " _
                & strDoc & ". Please update manually."
            End If
          End If
        End If
      Else
        ' Output a 'protected' file report in the document from which the macro is run.
        ThisDocument.Range.InsertAfter vbCr & strDoc & " protected. Not updated."
      End If
      .Close SaveChanges:=True
    End With
    ' Update the main file counter
    j = j + 1
    ' Let Word do its housekeeping
    DoEvents
    ' Reset the file's Date/Time stamp.
    Set oItem = FSO.GetFile(strDoc)
    If oItem.DateLastModified <> StrDtTm Then oItem.DateLastModified = StrDtTm
    Set oItem = Nothing
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    I replaced the code with the one you kindly sent and once again ran the macro for the same person's folder.

    This time the code ran much more slowly and displayed, for example:

    Contacting ||TSLSERVER\FilesR\Files\Doc\Gen\Word2002\Bill of Costs_02.dot

    I am unsure of where the extra folder 'FilesR' has come from. It is not in the code, nor on the File Server.

    Eventually the macro 'crashed' with the following error:

    Run-time error '450'
    Wrong number of arguments or invalid property assignment

    Debug highlighted the following:

    oItem.DateLastModified = StrDtTm

    The error report listed 29 files that it was unable to update and that should be updated manually. Most were Error '5180' files, but some were protected documents. I have been able to open all of these protected documents and I can see that they contain forms with editable fields that have been downloaded from say the Titles Office and I am unable to see which templates are attached, as the document is just re-displayed when I got to Files | Options | Add-Ins | Templates.

    Regards
    George

  11. #71
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,769
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Hi George,

    Like you, I can't see where "the extra folder 'FilesR' has come from". Perhaps it's because the offending template's path was formerly specified as "\\TSB\VOL1R".

    As for the "Run-time error 450", you could replace the lines:
    Set oItem = FSO.GetFile(strDoc)
    StrDtTm = oItem.DateLastModified
    with:
    StrDtTm = FileDateTime(strDoc)
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    As far as I know, the path has never been \\TSB\Vol1R ... so that extra folder \FilesR\ remains a mystery.

    I have replaced the code as you suggested and ran the macro yet again on the same folder. It ran for a while then it 'crashed', this time with the following error:

    Run-time error '6295'
    Office has detected a problem with this file. To help protect your computer this file cannot be opened.

    Debug highlighted:

    Documents.Open StrDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto

    When I then opened this file, it was opened in Protected Mode, with a similar error in Word.

    Regards
    George

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

    I keep forgetting to ask if you know what the problem is with the date fix macro?

    Regards
    George

  14. #74
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,769
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Hi George,

    Re the file with problem contents, that suggests a corrupt document. There's really nothing I can do to fix that. I can, however, add extra error-checking:
    Code:
    Sub UpdateTemplateRefs(strDoc As String)
    ' This sub updates the template paths for files after a server
    ' change. Simply insert however much of the lower end of the
    ' server paths differ as the OldServer and NewServer variables.
    Dim OldServer As String, NewServer As String, strPath As String
    Dim oItem As Object, StrDtTm As String
    OldServer = "\\TSB\VOL1": NewServer = "\\TSLSERVER\Files"
    ' Store the file's current Date/Time stamp.
    StrDtTm = FileDateTime(strDoc)
    ' Disable auto macros
    WordBasic.DisableAutoMacros = True
    On Error GoTo ErrRpt
    ' Open the document
    Documents.Open strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto
    With ActiveDocument
      If .ProtectionType = wdNoProtection Then
        ' Update the template path
        strPath = Dialogs(wdDialogToolsTemplates).Template
        If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then
          ' Update the file counter for changed files
          i = i + 1
          ' Get the new template path & name
          strPath = NewServer & Mid(strPath, Len(OldServer) + 1)
          ' Check whether the template exists
          If Dir(strPath) <> "" Then
            ' If found, update the path
            .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
          Else
            ' If not found, reset the template to 'Normal'
            .AttachedTemplate = ""
            ' Output an error report in the document from which the macro is run.
            ThisDocument.Range.InsertAfter vbCr & "Template: " & strPath & " not found for " & strDoc
    ErrRpt:
            ' Output error reports in the document from which the macro is run.
            If Err.Number = 5180 Then
              ThisDocument.Range.InsertAfter vbCr & "Err 5180 - Template: " & strPath & " could not be updated for " _
                & strDoc & ". Please update manually."
            ElseIf Err.Number = 6295 Then
              ThisDocument.Range.InsertAfter vbCr & "Err 6295 - Unable to open " & strDoc & ". Office detected a problem with this file."
            ElseIf Err.Number > 0 Then
              ThisDocument.Range.InsertAfter vbCr & "Unspecified error - Template: " & strPath & " could not be updated for " _
                & strDoc & ". Please update manually."
            End If
          End If
        End If
      Else
        ' Output a 'protected' file report in the document from which the macro is run.
        ThisDocument.Range.InsertAfter vbCr & strDoc & " protected. Not updated."
      End If
      .Close SaveChanges:=True
    End With
    ' Update the main file counter
    j = j + 1
    ' Let Word do its housekeeping
    DoEvents
    ' Reset the file's Date/Time stamp.
    If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oItem = FSO.GetFile(strDoc)
    If oItem.DateLastModified <> StrDtTm Then oItem.DateLastModified = StrDtTm
    Set oItem = Nothing
    ' Enable auto macros
    WordBasic.DisableAutoMacros = False
    End Sub
    Re the date-fix macro, I wasn't aware there was a problem with it. Post #54 suggested the code in post #52 worked fine.
    Last edited by macropod; 2012-12-02 at 15:36.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    I thought the date-fix issue might get lost in all our correspondence. You are right, I tested it and it initially worked (Post #54), but when I ran it on the real files, it ran for a while and eventually 'crashed'. If you look at my Post #59 you will see the problem.

    Thank you for the new code. I will implement it today and let you know the result.

    I am very grateful for your continued help!

    Regards
    George

Page 5 of 6 FirstFirst ... 3456 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
  •