• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

run-time error 13 type mismatch

Stephen Spittal

New Member
Hello all,

I am using the code below to open all the linked sources for my excel spreadsheet

however on the line
Code:
For I = 1 to UBound(v)

I get a run-time error 13 type miss match

Code:
Sub UpdateLinks()
  Dim v As Variant, i As Long
  v = ThisWorkbook.LinkSources(XlLink.xlExcelLinks)
  For i = 1 To UBound(v)
  If Not FileInUse(v(i)) Then
  Workbooks.Open (v(i))
  End If
  Next i
  ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
End Sub

Public Function FileInUse(sFileName) As Boolean 'Checks if a workbook is open
  On Error Resume Next
  Open sFileName For Binary Access Read Lock Read As #1
  Close #1
  FileInUse = IIf(Err.Number > 0, True, False)
  On Error GoTo 0
End Function

any help would be much apprecisated
 
Hi ,

Try this :
Code:
Sub UpdateLinks()
    Dim v As Variant, i As Long
    v = ThisWorkbook.LinkSources(XlLink.xlExcelLinks)
    If Not IsEmpty(v) Then
      For i = 1 To UBound(v)
          If Not FileInUse(v(i)) Then Workbooks.Open (v(i))
      Next i
      ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
    End If
End Sub
Narayan
 
Back
Top