Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao,
per verificare se un file excel (che non sia condiviso) è aperto potresti utilizzare questa Function (di Chip Pearson):
Public Function IsFileOpen(FileName As String) As Boolean
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IsFileOpen
' By Chip Pearson www.cpearson.com/excel ******@cpearson.com
' This function determines whether a file is open by any program. Returns TRUE or FALSE
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim FileNum As Long
Dim ErrNum As Long
On Error Resume Next ' Turn error checking off.
'''''''''''''''''''''''''''''''''''''''''''
' If we were passed in an empty string,
' there is no file to test so return FALSE.
'''''''''''''''''''''''''''''''''''''''''''
If FileName = vbNullString Then
IsFileOpen = False
Exit Function
End If
'''''''''''''''''''''''''''''''
' If the file doesn't exist,
' it isn't open so get out now.
'''''''''''''''''''''''''''''''
If Dir(FileName) = vbNullString Then
IsFileOpen = False
Exit Function
End If
''''''''''''''''''''''''''
' Get a free file number.
''''''''''''''''''''''''''
FileNum = FreeFile()
'''''''''''''''''''''''''''
' Attempt to open the file
' and lock it.
'''''''''''''''''''''''''''
Err.Clear
Open FileName For Input Lock Read As #FileNum
''''''''''''''''''''''''''''''''''''''
' Save the error number that occurred.
''''''''''''''''''''''''''''''''''''''
ErrNum = Err.Number
On Error GoTo 0 ' Turn error checking back on.
Close #FileNum ' Close the file.
''''''''''''''''''''''''''''''''''''
' Check to see which error occurred.
''''''''''''''''''''''''''''''''''''
Select Case ErrNum
Case 0
'''''''''''''''''''''''''''''''''''''''''''
' No error occurred.
' File is NOT already open by another user.
'''''''''''''''''''''''''''''''''''''''''''
IsFileOpen = False
Case 70
'''''''''''''''''''''''''''''''''''''''''''
' Error number for "Permission Denied."
' File is already opened by another user.
'''''''''''''''''''''''''''''''''''''''''''
IsFileOpen = True
Case Else
'''''''''''''''''''''''''''''''''''''''''''
' Another error occurred. Assume the file
' cannot be accessed.
'''''''''''''''''''''''''''''''''''''''''''
IsFileOpen = True
End Select
End Function
FileName è rappresentato dal "FullName" (quindi compreso il percorso dove si trova il file e il nome del file, compresa l'estensione).
Es. D:\Test\Cartel1.xlsx
Poi le soluzioni da adottare possone essere differenti e a gusto.
Ad es. all'apertura del file di "data entry" potresti, prima di aprire il file database, verificare se il file è aperto e se lo è avvisare l'utente che non è possibile operare e chiudere il file di "data entry".
Potresti comunque mantenere i file data entry aperto ma non consentire di far partire la procedura che memorizza i dati (sempre lanciando un avviso che il file database è temporaneamente utilizzato da altri e che occorre attendere).
Potresti lanciare un "loop" che per un certo tempo cerchi di aprire il file fino a che non diventa "disponibile", magari interrompendosi dopo che sia trascorso un tot di tempo in maniera automatica e avvisando che non è stato possibile aprire il database.
Dipende da quale è la tua preferenza in base alle tue esigenze.