Pwbrown7333
New Member
- Joined
- Nov 18, 2021
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
Disclosure: I am not a programmer by trade... picked up somethings here and there so will caution all that my coding may be "clunky" at best and could be using older language. Digging on line and multiple google questions and looking at options has probably not been the best way to go, but I am open to try different code ways... as long as I can understand and ultimately use.
Background: Files on a sharepoint site and the files require us to open the file in actual excel app and not use the online version (macros/vba/etc) that the online does not support
Issue: Mutiple people can get in the file and unless users watch for people, we have had issues with data being overwritten, etc.
Solution: Been able to develop some VBA that unless you are the first to open the file a prompt comes up tell you the file is already open and gives the choice to open read only or to close
Current issues:
1 - When converting to read only (code being used below), we get a prompt asking if we want to save before converting to read only. Either need to auto click NO or disable this prompt all together
Code currently used for converting....
2 - If the user clicks "NO" and does open in read only.... if they do make modifications and close the file, it still asks if they want to "Would you like to merge your changes with the latest updates on the server?". Now, we have tested and if they click "Yes", we have not seen any changes to the file online, however we don't want to cause confusion. Therefore, we would like to either auto click "NO" or disable this prompt as well.
Code being used at the before close.....
Any help/guidance/assistance is greatly appreciated!
Background: Files on a sharepoint site and the files require us to open the file in actual excel app and not use the online version (macros/vba/etc) that the online does not support
Issue: Mutiple people can get in the file and unless users watch for people, we have had issues with data being overwritten, etc.
Solution: Been able to develop some VBA that unless you are the first to open the file a prompt comes up tell you the file is already open and gives the choice to open read only or to close
Current issues:
1 - When converting to read only (code being used below), we get a prompt asking if we want to save before converting to read only. Either need to auto click NO or disable this prompt all together
Code currently used for converting....
VBA Code:
If MsgBox("Open in Read Only?", vbYesNo, "File Open By Another User") = 6 Then
ThisWorkbook.ChangeFileAccess Mode:=xlReadOnly
Else
ActiveWorkbook.Close savechanges:=False
Application.Quit
2 - If the user clicks "NO" and does open in read only.... if they do make modifications and close the file, it still asks if they want to "Would you like to merge your changes with the latest updates on the server?". Now, we have tested and if they click "Yes", we have not seen any changes to the file online, however we don't want to cause confusion. Therefore, we would like to either auto click "NO" or disable this prompt as well.
Code being used at the before close.....
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim UserClose As Excel.Worksheet
Set UserClose = ActiveWorkbook.Worksheets("User")
UserClose.Activate
Worksheets("user").Visible = True
Worksheets("user").Select
Range("B1").Select
Worksheets("user").Select
Range("B1").Value = Environ$("username")
If Range("A1") = Range("B1") Then
If MsgBox("Save File?", vbYesNo, "Saving Option") = 6 Then
UserClose.Activate
Worksheets("user").Select
Range("A1").Clear
Worksheets("user").Select
Range("A4").Clear
Worksheets("user").Select
Range("B1").Clear
Worksheets("user").Visible = False
ThisWorkbook.Save
Application.Quit
Else
UserClose.Activate
Worksheets("user").Select
Range("A1").Clear
Worksheets("user").Select
Range("A4").Clear
Worksheets("user").Select
Range("B1").Clear
Worksheets("user").Visible = False
ActiveWorkbook.Close savechanges:=False
Application.Quit
End If
ElseIf Range("A1") <> Range("B1") Then
ActiveWorkbook.Close savechanges:=False
Application.Quit
End If
Any help/guidance/assistance is greatly appreciated!