ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Best way to check (https://www.excelbanter.com/excel-programming/354307-best-way-check.html)

Ricardo Silva[_2_]

Best way to check
 
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


Tom Ogilvy

Best way to check
 
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

--
Regards,
Tom Ogilvy


"Ricardo Silva" wrote in message
...
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




Ricardo Silva[_2_]

Best way to check
 
Wonderfull!
Thanks a lot Tom

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Ricardo Silva" wrote in message
...
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






All times are GMT +1. The time now is 05:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com