|
▼siga さん:
↓からサンプルコード拝借してみました。
http://support.microsoft.com/default.aspx?scid=kb%3Bja%3B291295
ローカルなら、いけましたが試してみてください。
Option Explicit
Sub Test()
Dim myFile As String
Dim i As Integer
myFile = ThisWorkbook.Path & "\Test.csv"
i = 0
Do Until IsFileOpen(myFile) = False
Application.Wait (Now + TimeValue("0:00:01"))
i = i + 1
If i >= 10 Then Exit Do
Loop
If i >= 10 Then MsgBox "タイムアウトしました": Exit Sub
Workbooks.Open (myFile)
End Sub
Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer
On Error Resume Next
filenum = FreeFile()
Open filename For Input Lock Read As #filenum
Close filenum
errnum = Err
On Error GoTo 0
Select Case errnum
Case 0
IsFileOpen = False
Case 70
IsFileOpen = True
Case Else
Error errnum
End Select
End Function
|
|