Salam B-Exceller,
Mohon bimbingannya.
Ada file di server network yang kadang dibuka oleh seseorang. Saya ingin tahu 
pada hitungan 3 menit ke berapa file itu ditutup. Jadi ketika file itu sedang 
dibuka, tunggu sampai 3 detik. Kalau 3 detik pertama file masih terbuka, tunggu 
3 detik ke dua, dst.

Ini code vba yang saya sudah tulis.

Sub Button3_Click()
Call cekfilenya
MsgBox "File ditutup"
End Sub

Sub cekfilenya()
Dim InUse
Dim CloudDbFile As String
Dim j As Byte

J=0
CloudDbFile = “Y:\1. Folder Dataku\CustData.xlsx”
InUse = IsWorkBookOpen(CloudDbFile)
        Do Until InUse = False
            Application.Wait (Now + TimeValue("0:00:03"))
            MsgBox "Hitungan ke " & j
            j = j + 1
        Loop
If InUse = True Then
        Exit Sub
  End If
End Sub

Function IsWorkBookOpen(FileName As String)
Dim ff As Long, ErrNo As Long

On Error Resume Next
ff = FreeFile()
Open FileName For Input Lock Read As #ff
Close ff
ErrNo = Err
On Error GoTo 0

Select Case ErrNo
Case 0: IsWorkBookOpen = False
Case 70: IsWorkBookOpen = True
Case Else: Error ErrNo
End Select
End Function


Terima kasih atas bimbingannya.
Salam.


Kirim email ke