Notifications
Clear all

Controle de acessos

2 Posts
2 Usuários
0 Reactions
965 Visualizações
(@emilitao)
Posts: 0
New Member
Topic starter
 

Bom dia, pessoal!

Tenho uma planilha que várias pessoas utilizam e gostaria de incrementar um controle de acessos. Encontrei uma macro que faz este controle, porém quero acrescentar o registro do usuário e da máquina que está fazendo-o. Alguém pode me dizer como? Segue macro:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim wsHist As Worksheet, Rng As Range
Set wsHist = Sheets("História")
If Sh Is wsHist Then Exit Sub
Set Rng = wsHist.Range("A" & Rows.Count).End(xlUp).Offset(1)
With Rng
.Value = Now
.Offset(, 1) = Sh.Name
.Offset(, 2) = Target.Address
If Target.Cells.Count > 1 Then
.Offset(, 3) = "Valores Alterados"
Else
.Offset(, 3) = Target.Formula
End If
End With
End Sub

Desde já, agradeço.

Eudes Militão

 
Postado : 02/11/2015 7:19 am
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

EMilitão,

Boa Tarde!

Altere para esse código:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim wsHist As Worksheet, Rng As Range
    Set wsHist = Sheets("História")
    If Sh Is wsHist Then Exit Sub
    Set Rng = wsHist.Range("A" & Rows.Count).End(xlUp).Offset(1)
    With Rng
        .Value = Now
        .Offset(, 1) = Sh.Name
        .Offset(, 2) = Target.Address
        .Offset(, 3) = VBA.Environ("UserName")
        .Offset(, 4) = VBA.Environ("COMPUTERNAME")
        If Target.Cells.Count > 1 Then
            .Offset(, 5) = "Valores Alterados"
        Else
            .Offset(, 5) = Target.Formula
        End If
    End With
End Sub
 
Postado : 02/11/2015 10:09 am