-1

I have
1. A shared excel sheet
2. Html page with VBscript

I want to execute a part of code(saving some data in shared excel) such that only one user (the one who opened that shared excel first) at a time can do it.

I trying many things. But its not working as expected.

Any help will be appreciated.

Anurag Rana
  • 1,429
  • 2
  • 24
  • 48
  • Please show what you've tried. We may be able to improve you current method/s. – glh Apr 19 '13 at 09:50
  • 1
    Please see this http://stackoverflow.com/questions/9373082/detect-whether-excel-workbook-is-already-open-using-vba/9373914#9373914 – Siddharth Rout Apr 19 '13 at 10:21

1 Answers1

0

The following vba will check to see if the file is open.

Dim FileNum As Integer

'File exists
If Len(Dir(StrFilePath)) > 0 Then 
    FileNum = FreeFile() 
    On Error Resume Next 
    Open StrFilePath For Input Lock Read As #FileNum 
    'Open and lock file
    If Err.Number <> 0 Then 
        'File is open
    Else 
        'File is closed
    End If 
    Close FileNum 
    On Error GoTo 0
Else 
    'File does not exist
End If
glh
  • 4,900
  • 3
  • 23
  • 40