View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Francis Brown Francis Brown is offline
external usenet poster
 
Posts: 57
Default Opening and Closing workbooks in code

The only people who will get the password to the workbooks for the data will
be admin. All other people will use the excel userforms. I will lock the code
and add passwords for the databook.

I know I need to add the password part to the code.

That would only leave if the code breaks to cause the problem you described.
--
Regards and Thanks for any assistance.

Francis Brown.


"Rowan Drummond" wrote:

Hi Francis

Happy to help.

Without actually testing your code it looks like you could get into a
very long loop eg if somebody else has the file open for an hour (or all
day!!) this looks like it will continue to open and close the file as
read only until the other user closes it?

Regards
Rowan

Francis Brown wrote:
Hello.

Thanks for answer. It worked with slight alteration. Thanks for getting me
on right track.

heres my code :

Private Sub CommandButton1_Click()

Do Until issave = True
Dim theBk As Workbook
Set theBk = Workbooks.Open("Z:\Systemdown\Declaration.xls")
If theBk.ReadOnly Then
theBk.Close False
issave = False
Else
newrow =
Workbooks("Declaration.xls").Sheets("data").Range( "A65536").End(xlUp).Row + 1
Workbooks("Declaration.xls").Sheets("data").Cells( newrow, 1).Value
= TextBox1.Value
Workbooks("Declaration.xls").Sheets("data").Cells( newrow, 2).Value
= TextBox2.Value
Workbooks("Declaration.xls").Sheets("data").Cells( newrow, 3).Value
= TextBox3.Value
Workbooks("Declaration.xls").Sheets("data").Cells( newrow, 4).Value
= TextBox4.Value

theBk.Close True
MsgBox "Records Saved"
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
issave = True

End If
Loop

End Sub