Read Only Files

CliveBurt01

New Member
Joined
Aug 6, 2014
Messages
1
Dear Excel supremos

When a work sheet opens I want to test whether the person opening it has it opened as read only or not.
If they have the file as Read/Write, the macro goes away and records their logon id and when they opened the file, they should then go to the logon page, and detail any changes ot the spreadsheet that they have made in the area that has been set up for this .... a sort of version control, where at least I know who's opened the file as Read/Write ....

What I would like to do next is chancge the macro so that it tests whether the file has been opened as Read Only, and if it has, allow them access without recording anything .... i.e. they can look but not able to overwrite the file.

How do I do this?

The Macros/VBA I have written (with the help of a former colleague is as follows:

Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long
Sub Get_User_Name()

Dim lpbuff As String * 25
Dim ret As Long, UserName As String
ret = GetUserName(lpbuff, 25)
UserName = Left(lpbuff, InStr(lpbuff, Chr(0)) - 1)
MsgBox UserName

End Sub

Sub Auto_Open()
Dim lpbuff As String * 25
Dim ret As Long, UserName As String
Dim strName As String
ActiveWorkbook.ReadOnly

unprotect_log
ret = GetUserName(lpbuff, 25)
Worksheets("Log").Select
Range("a1").Select
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = Left(lpbuff, InStr(lpbuff, Chr(0)) - 1)
ActiveCell.Offset(0, 1).Value = Now
ActiveCell.Offset(0, 1).Select
PROTECT_LOG
Worksheets(1).Select
End Sub

Sub PROTECT_LOG()
'
' PROTECT_LOG Macro
'

Worksheets("Log").Select
ActiveSheet.Protect
Application.Goto Reference:="R1C1"
ActiveWorkbook.Save


End Sub

Sub unprotect_log()
Worksheets("Log").Select
ActiveSheet.Unprotect
Application.Goto Reference:="R1C1"
ActiveWorkbook.Save

End Sub

Sub Auto_Close()
PROTECT_LOG
Worksheets(1).Select
Application.Goto Reference:="R1C1"
ActiveWorkbook.Save
End Sub


I realise that I will have to create an alternative Auto-Open() VBA routine, just not sure on how to test for the Read Only condition, and then what happens from there .....

Regards

Clive
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top