How to I get a warning message box

S

shrek

I have a shared workbook and when I enter it sometimes its read only.
Not realising I input data and then when I come to save it tells me to
save as.

Is there anyway you can get a box to pop up saying its read only and
you have to click on ok to clear it when you open the file.
 
R

Roger Govier

Hi Shrek

Here is some code I use for that purpose.
Adapt to suit your needs.

Sub OpenPurch()
'
' Open Purchase Ledger routine
strPath = ActiveWorkbook.Path
StrDrive = Left(strPath, 1)
TestPLedg
'Check if file is already open
If ActiveWorkbook.ReadOnly = True Then
MsgBox "The Purchase Ledger file is currently in use by another
user." & _
Chr(10) & "You cannot Enter any Data until you have a Write
Access." _
& Chr(10) & Chr(10) & "You can use the file to VIEW data only"
End If
Sheets("Data Entry").Select

End Sub

Sub TestPLedg()
On Error Resume Next
Dim Opfile As String
Dim wkname As String
'
Opfile = strPath & "\Pledg.xls"
wkname = Workbooks("Pledg.xls").Name
If Len(wkname) = 0 Then
Workbooks.Open filename:=Opfile
End If
Workbooks("Pledg.xls").Activate
On Error GoTo 0
End Sub



Regards

Roger Govier
 
S

shrek

Many thanks for that just one other question.

Do I set this up as a new seperate macro in the workbook or set it up
within the macro used to open the workbook.

Thanks
 
R

Roger Govier

Hi

You would need to use this in place of your macro, but change the file name
and sheet names to suit your case.

Regards

Roger Govier
 
Top