Hi All,
I have used the following code I found online in my current project so that if the file it is trying to write to is being read by someone else, then it displays a prompt. It keeps on re-trying until the file is no longer read only. Finally it will write and save to the file and display a message saying it has been submitted.
However, as I have excel hidden so that only the userform shows, the debug.print line doesn't work. So i tried to change it to a msgbox, but that doesn't work for me, as it then requires the user to click on the okay button, wait 5 seconds to see if it has gone through or not and then repeat.
I also tried a show userform method, but that didn't work. I don't know why.
I had was
Pleasewait.Show
in place of
Debug.Print "If not closed, close the original ReadWrite version now."
and Unload Pleasewait
in place of
Debug.Print "Read write version should be ready now."
The Pleasewait userform is a simple label stating that they will have to wait as the file is being used by someone else.
Can someone please help me? Thanks in advance.
Dips.
I have used the following code I found online in my current project so that if the file it is trying to write to is being read by someone else, then it displays a prompt. It keeps on re-trying until the file is no longer read only. Finally it will write and save to the file and display a message saying it has been submitted.
Code:
Private Sub workbookRW()
Dim xlApp As Object
Dim wbTEST As Object
Dim wbRO As Boolean
Dim start As Date
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set wbTEST = xlApp.Workbooks.Open("h:\Test\Test.xlsx")
start = Now
If wbTEST.ReadOnly Then
Do Until Not wbTEST.ReadOnly
wbTEST.Close savechanges:=False
Do Until Now > start + TimeValue("0:00:05")
Loop
Debug.Print "If not closed, close the original ReadWrite version now."
Set wbTEST = xlApp.Workbooks.Open("h:\Test\Test.xlsx")
start = Now
Loop
End If
Debug.Print "Read write version should be ready now."
ExitRoutine:
Set wbTEST = Nothing
Set xlApp = Nothing
End Sub
However, as I have excel hidden so that only the userform shows, the debug.print line doesn't work. So i tried to change it to a msgbox, but that doesn't work for me, as it then requires the user to click on the okay button, wait 5 seconds to see if it has gone through or not and then repeat.
I also tried a show userform method, but that didn't work. I don't know why.
I had was
Pleasewait.Show
in place of
Debug.Print "If not closed, close the original ReadWrite version now."
and Unload Pleasewait
in place of
Debug.Print "Read write version should be ready now."
The Pleasewait userform is a simple label stating that they will have to wait as the file is being used by someone else.
Can someone please help me? Thanks in advance.
Dips.