Salam BeExceller,
Saya sudah menemukan coding vb untuk mengetahui apakah file yang saya pilih 
sudah dibuka atau tidak. Tapi code vba tsb dimaksudkan file terbuka di computer 
kita dan terbuka juga di network oleh orang lain.
Bisakah kita memodif code vba untuk mengetahui apakah file yang dimaksud sudah 
terbuka HANYA di computer kita sendiri (bukan terbuka di network oleh user 
lain) ?

Dibawah adalah code vba yang mengetahui apakah file dimaksud sudah 
terbuka/tidak oleh kita sendiri dan user lain di network.

Sub TestFileOpened()

    ' Test to see if the file is open.
    If IsFileOpen("\\ssbfs01\ssbstore\Corporate Division\Estimating 
Department-Services\2. Estimator\8. Tio\Nozzle-Type-Information.xlsx") Then
        ' Display a message stating the file in use.
        MsgBox "File already in use!"
        '
        ' Add code here to handle case where file is open by another
        ' user.
        '
    Else
        ' Display a message stating the file is not in use.
        MsgBox "File not in use!"
        ' Open the file in Microsoft Excel.
'        Workbooks.Open "c:\Book2.xls"
        '
        ' Add code here to handle case where file is NOT open by another
        ' user.
        '
    End If

End Sub

' This function checks to see if a file is open or not. If the file is
' already open, it returns True. If the file is not open, it returns
' False. Otherwise, a run-time error occurs because there is
' some other problem accessing the file.

Function IsFileOpen(filename As String)
    Dim filenum As Integer, errnum As Integer

    On Error Resume Next   ' Turn error checking off.
    filenum = FreeFile()   ' Get a free file number.
    ' Attempt to open the file and lock it.
    Open filename For Input Lock Read As #filenum
    Close filenum          ' Close the file.
    errnum = Err           ' Save the error number that occurred.
    On Error GoTo 0        ' Turn error checking back on.

    ' Check to see which error occurred.
    Select Case errnum

        ' No error occurred.
        ' File is NOT already open by another user.
        Case 0
         IsFileOpen = False

        ' Error number for "Permission Denied."
        ' File is already opened by another user.
        Case 70
            IsFileOpen = True

        ' Another error occurred.
        Case Else
            Error errnum
    End Select

End Function


Thanks,
Tio
__,_._,_
  • [belajar-excel] M... Tio Adi Bayu Adjie tio.ad...@ptssb.co.id [belajar-excel]
    • Re: [belajar... 'Mr. Kid' mr.nm...@gmail.com [belajar-excel]
      • RE: [bel... Tio Adi Bayu Adjie tio.ad...@ptssb.co.id [belajar-excel]

Kirim email ke