Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies. Only from Platform Scholar.
Sub openfile() Dim wkdir as string, openworkbookname as string wkdir="C:\" k=0 Do until k=100 openfileworkname= k&".htm" If CheckFileAvailable(wkdir & openworkbookname) = "Fileinfree" Then 'Sleep(100) 'Application.EnableEvents = False 'ClearClipboard Excel.Application.Workbooks.Open filename:=wkdir & openworkbookname, ReadOnly:=False Doevent or ... 'Application.EnableEvents = True Endif k=k+1 Loop End Sub Function CheckFileAvailable(sFilePath) On Error Resume Next Dim oFS Dim oFile Set oFS = CreateObject("Scripting.FileSystemObject") Set oFile = oFS.OpenTextFile(sFilePath, 8, False) If Err.Number <> 0 Then CheckFileAvailable = "Fileinuse" ' Debug.Print "FileinUse" Else CheckFileAvailable = "Fileisfree" Debug.Print "FileisFree" End If End Function Public Function ClearClipboard() OpenClipboard (0&) EmptyClipboard CloseClipboard End Function
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.