» Determine if a file is in use using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Files, Workbook, and Worksheets in VBA
VERSION - All Microsoft Excel Versions
The function returns True if you can't get full access to the file.
Function FileAlreadyOpen(FullFileName As String) As Boolean
' returns True if FullFileName is currently in use by another process
' example: If FileAlreadyOpen("C:\FolderName\FileName.xls") Then...
Dim f As Integer
f = FreeFile
On Error Resume Next
Open FullFileName For Binary Access Read Write Lock Read Write As #f
Close #f
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
FileAlreadyOpen = True
Err.Clear
'MsgBox "Error #" & Str(Err.Number) & " - " & Err.Description
Else
FileAlreadyOpen = False
End If
On Error GoTo 0
End Function
Book Store:
Recommended Books:
- Flipping Properties: Generate Instant Cash Profits in Real Estate
- Rich Dad, Poor Dad: What the Rich Teach Their Kids About Money--That the Poor and Middle Class Do Not!
- Excel 2002 For Dummies®
- Final Accounting: Ambition, Greed and the Fall of Arthur Andersen
- Financial Shenanigans : How to Detect Accounting Gimmicks & Fraud in Financial Reports
- Managerial Accounting: Tools for Business Decision Making, WebCT, 2nd Edition
No comments have been submitted.

