+ Reply to Thread
Results 1 to 11 of 11

insert who accesses in the workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    insert who accesses in the workbook

    Hello everyone.
    In the attached workbook there are macros in thisworkbook:
    in Private Sub Workbook_Open()
    
     '---------------------------------------------------------------------------
     'ACCESSI
     
     Dim nomefoglio As Variant
        Dim Urec   As String
    
        Application.ScreenUpdating = False
        Application.EnableEvents = False            '<-aggiunta
       
        'With Sheets("ACCESSI")
           ' nomefoglio = .Cells(10000, "II")
           ' Sheets(nomefoglio).Activate             '<<< apre il foglio e sprotegge
         
        With Sheets("ACCESSI")                         '<<< apre il foglio e sprotegge
            .Unprotect "987654"
            .Cells(10000, "II") = ActiveSheet.Name
            .Unprotect "987654"
           
            'Urec = .Cells(Rows.Count, 52).End(xlUp).Row + 1
            '.Cells(Urec, 52) = Application.UserName
            '.Cells(Urec, 53) = Now
            '.Cells(Urec, 54) = "ACCESSO"
           
            Urec = .Cells(Rows.Count, 1).End(xlUp).Row + 1
            .Cells(Urec, 1) = Application.UserName
            .Cells(Urec, 2) = Now
            .Cells(Urec, 3) = "ACCESSO"
           
            .Protect "987654"
        End With
        Application.ScreenUpdating = True
        Application.EnableEvents = True             '<-aggiunta
       
         
      '---------------------------------------------------------------------------
    and in:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    
    '---------------------------------------------------------------------------
     'ACCESSI
       
        Dim nomefoglio As Variant
        Dim Urec   As String
    
        Application.ScreenUpdating = False
        Application.EnableEvents = False            '<-aggiunta
        With Sheets("ACCESSI")                         '<<< apre il foglio e sprotegge
            .Unprotect "987654"
            .Cells(10000, "II") = ActiveSheet.Name
           
            'Urec = .Cells(Rows.Count, 52).End(xlUp).Row + 1
            '.Cells(Urec, 52) = Application.UserName
            '.Cells(Urec, 53) = Now
            '.Cells(Urec, 54) = "FINE SESSIONE"
           
             Urec = .Cells(Rows.Count, 1).End(xlUp).Row + 1
            .Cells(Urec, 1) = Application.UserName
            .Cells(Urec, 2) = Now
            .Cells(Urec, 3) = "FINE SESSIONE"
           
            .Protect "987654"
        End With                                    '<<< ritorna al foglio
        ThisWorkbook.Save                                       'salva
        If SoloVisione = True Then ThisWorkbook.Saved = False   'se ci sono stati interventi proponi popup Salva
        Application.ScreenUpdating = True
        Application.EnableEvents = True             '<-aggiunta
                 
    '------------------------------------------------------------------------------------------------------

    which are used to enter in the "ACCESSI" sheet whoever accesses the workbook.
    Also in this workbook there is a macro:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    '------------------------------------------------------------------------------------------------------
    'per utente autorizzato
    
    Dim avviso As String
    Dim cercarange As Range
    
         
    
        Set cercarange = Foglio8.Range("E2:E11").Find(Foglio8.Range("F2"))
         
    
        If cercarange Is Nothing Then
       
       
          ' MsgBox "Value not found"
          avviso = MsgBox(Environ("UserName") & " non sei autorizzato a modificare questo workbook", vbCritical + vbDefaultButton2, "AVVISO!")
    
            If avviso = vbOK Then
    
          Me.Saved = True
    
    Exit Sub
    
    
    
        ' MsgBox "Value not found"
        'ThisWorkbook.Saved = True
        ' ThisWorkbook.Close
    
    
        Else
    
            'MsgBox foundRng.Address
    
        End If
    
    
    End If
    '---------------------------------------------------------------------------
    to authorize the use of the workbook to certain users who are in the sheet "utenti_errori" column E

    There is a problem:

    if changes are made and at closing I say "do not save" these changes remain.
    Help to correct?
    I hope I have explained.
    xam
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: insert who accesses in the workbook

    ignore - misread the issue

  3. #3
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: insert who accesses in the workbook

    I badly explained myself?
    Sorry for my English

  4. #4
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: insert who accesses in the workbook

    Hello on the net I found

    Private Sub Workbook_BeforeClose(Cancel As Boolean)  
        
    '------------------------------------------------------------------------------
    
    Dim info As String
        string1 = ThisWorkbook.BuiltinDocumentProperties("content status").Value
        If info = "ACCESSI" Then
    
            ThisWorkbook.BuiltinDocumentProperties("content status").Value = ""
            Application.DisplayAlerts = False
            ThisWorkbook.Save
        End If
        
    '---------------------------------------------------------------------------
    and in the sheet "AVVISI"

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        ThisWorkbook.BuiltinDocumentProperties("content status").Value = "ACCESSI"
    End Sub
    work well.

    Now how to insert the exact variable here?

    string1 = ThisWorkbook.BuiltinDocumentProperties("content status").Value

    long? variant? string.......
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: insert who accesses in the workbook

    Ops not work the modification the post# 4

  6. #6
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: insert who accesses in the workbook

    Basically what I ask is that if changes are made or not to the workbook, whoever makes the changes must be entered

  7. #7
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: insert who accesses in the workbook

    I'm lost as to some of the logic, but the attached has been chopped around a little more and rather than trying to handle everything in the Before_Close event the code has been split out so the Before_Save event is used to determine if the user can save or not.

    If the user is authorised to save then it just saves and will prompt to backup immediately after (I've not looked at that, and it may not be the best place for it).

    If the user is not authorised to save then the (Italian) 'You are not authorised...' message box will be displayed, the workbook Saved Flag is set to True to prevent other prompts before the next change and the procedure exits.

    In the Before_Close event, it again checks and if the user is not authorised it will prompt "Edits will not be saved..." and gives a choice to continue to close or keep the workbook open (in case they might need to copy changes, or whatever).

    I'm not saying this is the answer to your question but it is probably a better place to start from. To be honest, the best way to handle this would be to manipulate the ribbon and disable the Save options if the user is not authorised to save - this would greatly simplify things.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: insert who accesses in the workbook

    Hi cytop,
    what I'm looking for is this

    Basically what I ask is that if changes are made or not to the workbook, whoever makes the changes must be entered

  9. #9
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: insert who accesses in the workbook

    "...if changes are made or not to the workbook, whoever makes the changes must be entered..."

    I'm sorry. I'm confused but this is not what you posted in your first thread. Probably best if I leave it for someone else with a new perspective on this.

  10. #10
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: insert who accesses in the workbook

    Thanks the same cytop.

    The change is that I ask is in the post #6
    I hope I have explained

  11. #11
    Forum Contributor
    Join Date
    08-27-2019
    Location
    europa
    MS-Off Ver
    excel 2007
    Posts
    546

    Re: insert who accesses in the workbook

    Hello,
    is it possible to save only 1 sheet?
    So it doesn't work:

    Sheets("info").Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 05-21-2020, 07:36 AM
  2. [SOLVED] keep a log of who accesses a file and how many times
    By cmorten82 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-24-2018, 11:45 AM
  3. Custom Function now accesses a cell due to worksheet size increase in 2010 - How to fix?
    By Culleoka Al in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2013, 03:04 PM
  4. How to write a formula which accesses the just previous sheet
    By jsingh125 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2012, 07:35 AM
  5. Replies: 1
    Last Post: 02-01-2012, 08:03 AM
  6. Macro that accesses the a web page and copies the content
    By helixman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-04-2008, 01:31 AM
  7. [SOLVED] Tracking who accesses a spreadsheet
    By juamig in forum Excel General
    Replies: 1
    Last Post: 03-08-2006, 01:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1