Best way to check

R

Ricardo Silva

Hi.
I have a routine that opens all files linked to a specifc worbook, but if
one of the files is already open with changes done I get a message.
How can I check before trying to open? I have no idea what to do.
Thanks

My code is:

Private Sub CommandButton1_Click()
Dim thisFileName As String
Dim alinks As Variant
Dim i As Integer
thisFileName = ActiveWorkbook.Name
alinks = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(alinks) Then
For i = 1 To UBound(alinks)
MsgBox "Open file" & alinks(i) & "?", vbOKCancel
Workbooks.Open alinks(i)
Next i
End If
Workbooks(thisFileName).Activate
End Sub
 
T

Tom Ogilvy

Private Sub CommandButton1_Click()
Dim thisFileName As String
Dim alinks As Variant
Dim i As Integer
thisFileName = ActiveWorkbook.Name
alinks = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(alinks) Then
For i = 1 To UBound(alinks)
MsgBox "Open file" & alinks(i) & "?", vbOKCancel
On Error Resume Next
Application.DisplayAlerts = False
Workbooks.Open alinks(i)
Application.DisplayAlerts = True
On Error goto 0
Next i
End If
Workbooks(thisFileName).Activate
End Sub
 
R

Ricardo Silva

Wonderfull!
Thanks a lot Tom

Tom Ogilvy said:
Private Sub CommandButton1_Click()
Dim thisFileName As String
Dim alinks As Variant
Dim i As Integer
thisFileName = ActiveWorkbook.Name
alinks = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(alinks) Then
For i = 1 To UBound(alinks)
MsgBox "Open file" & alinks(i) & "?", vbOKCancel
On Error Resume Next
Application.DisplayAlerts = False
Workbooks.Open alinks(i)
Application.DisplayAlerts = True
On Error goto 0
Next i
End If
Workbooks(thisFileName).Activate
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top