The following vba opens an excel workbook checks to see if its in read-only mode, if it is then waits till read/write is active then runs code. Simple
My Questions is that I have a lot of excel files e.g C:\TEST\TEST.xlsb, C:\TEST\TEST2.xlsb ,C:\TEST\TEST3.xlsb ,C:\TEST\TEST4.xlsb etc
How do I get the VBA to run code through each workbook name
Save me time copy/pasting code several times for each workbook name.
Function test()
Dim xl As Object
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open ("C:\TEST\Test.xlsb")
Do Until xl.ActiveWorkbook.ReadOnly = False
MsgBox ("Workbook in use, waiting till read/write is active")
Call Pause(5)
xl.Quit
xl.Workbooks.Open ("C:\TEST\Test.xlsb")
If xl.ActiveWorkbook.ReadOnly = False Then Exit Do
Loop
If xl.ActiveWorkbook.ReadOnly = False Then
MsgBox ("read/write active")
'Run code
xl.Sheets("Sheet1").Range("G2").Value = 2222
xl.ActiveWorkbook.Save
xl.Quit
End If
xl.Quit
Set xl = Nothing
End Function