そこで、開くまで何度か試すようにコードを修正します。
Function FileOpen(FilePath As String, FileName As String, wb As Workbook) As Boolean
Dim fp As String
fp = FilePath & "\" & FileName
FileOpen = True
If Dir(fp) == "" Then
MsgBox "ファイルが存在しません。", vbExclamation
FileOpen = False
Exit Function
End If
On Error Resume Next
ReOpen_00:
Set wb = Workbooks.Open(FileName:=fp, Notify:=False, ReadOnly:=True)
' ここで何度か開きなおしてやる。
If Err.Number > 0 Then GoTo ReOpen_00
On Error GoTo 0
End Function
0 件のコメント:
コメントを投稿