

I’m guessing the examples in this post didn’t exactly meet your situation. If you’ve found this post useful, or if you have a better approach, then please leave a comment below.ĭo you need help adapting this to your needs? We’ll respect your privacy and you can unsubscribe at any time. Get our FREE VBA eBook of the 30 most useful Excel VBA macros.Īutomate Excel so that you can save time and stop doing the jobs a trained monkey could do.īy entering your email address you agree to receive emails from Excel Off The Grid. 'Call function to check if the file is open If IsFileOpen(fileName) = False Then 'Insert actions to be performed on the closed fileĮlse 'The file is open or another error occurred Sub CheckIfFileOpen()įileName = "C:\Users\marks\Documents\Already Open.xlsx" The following procedure shows how to call the above function. Remember: Functions must be placed into a Module to work correctly. IsFileOpen = True 'Something else went wrong Case Else 'errNum = 70 means the file is already open 'errNum = 0 means no errors, therefore file closed Case 0 'Do not allow errors to happen On Error GoTo 0 'Check the Error Number Select Case errNum 'Errors mean the file is already open Open fileName For Input Lock Read As #fileNum 'Try to open and close the file for input. Function IsFileOpen(fileName As String)ĭim fileNum As Integer Dim errNum As Integer 'Allow all errors to happen On Error Resume Next

That is why the 100 Excel VBA Macros eBook exists.

Therefore, what most people like you need is lots of examples that you can practice. The more you immerse yourself in that language, the faster you will pick it up. Apart from speaking, programming languages are no different. Do you know the fastest way to learn foreign languages? It is to read, write, speak, and think in that language as often as possible.
