Listing Updating Links with a New File Location

Sub FixLinks(wb As Workbook, sOldLink As String, sNewLink As String) On Error Resume Next wb.ChangeLink sOldLink, sNewLink, xlLinkTypeExcelLinks End Sub

If fixing links was the only thing you needed to do to a workbook, you could put the wb.Change-Link statement right in the ProcessFileBatch procedure. You may be tempted to do such a thing; however, be aware of the slight repercussion to doing so. The error-handling mechanism is different and you could have situations that warrant having separate error handling for both procedures.

Chances are that most of the time when FixLinks is called, an error will be generated. This is because you're not bothering to check if the workbook passed to FixLinks even contains any links, much less a link named the same as the sOldLink parameter. You could easily write a procedure that doesn't rely on error checking to do its job—check out Listing 6.5.

0 0

Post a comment