Read / Write issue on open a file

I have a file that sends information to another workbook to save information.
I have eventually managed to write the VB in 4 parts for ease.

1. Check Data
2. Open file
3. Copy to destination file
4. Clear sending file

The issue i am getting is that the copy to part has a 5 second delay to check if the destination file is read only.
If it is read only it loops back and tries to re open the file.
It does this fine, but when the file is not in use it gives me the read / write error.

As i am still learning VB i need to understand how to build the ok for this to re open the file and confirm it can be edited. I include the code below on the loop and re open

The error is when it re loops it ask for the password again instead of running the subcontinue properly.

[code]

Sub continue()

whichsheet = Range(“C6”).Value
MyMgr = Range(“B6”).Value

If MyMgr = “Mgr1” Then
Set myBook = Workbooks.Open(“file1.xls”, Password:=”alexmc”) ‘Work
Call start
‘ When already opened and then closed getting a read / write point from excel
Else
If MyMgr = “Mgr2” Then
Set myBook = Workbooks.Open(“file2.xls”, Password:=”alexmc”) ‘Work
Call start
Else
If MyMgr = “Mgr3” Then
Set myBook = Workbooks.Open(“file3.xls”, Password:=”alexmc”) ‘Work
Call start
Else
If MyMgr = “Mgr4” Then
Set myBook = Workbooks.Open(“\file4.xls”, Password:=”alexmc”) ‘Work
Call start
End If
End If
End If
End If

End Sub

[/code]

The code below puts the information into the correct sheet. I have removed where i have specified the code as string etc…

Leave a Reply

Your email address will not be published. Required fields are marked *