About Me
Com tecnologia do Blogger.
Seguidores
Estatisticas
2005-07-10
Por vezes, temos necessidade de criar um registo de entradas em determinado workbook, que, para além de conter o nome do utilizador, poderá ainda conter a data e a hora do acesso:

Resultado:

O Código:
Sub Auto_Open()
Dim Ops(1 To 5) As String
Dim msg As String
Ops(1) = Day(Date)
Ops(2) = Month(Date)
Ops(3) = Year(Date)
Ops(4) = Hour(Time)
Ops(5) = Minute(Time)
msg = Ops(3) & "-" & Ops(2) & "-" & Ops(1) & " " & Ops(4) & ":" & Ops(5)
Sheets("Sheet1").Select
Range("A65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Application.Cursor = xlNormal
Do While IsEmpty(ActiveCell)
ActiveCell.FormulaR1C1 = InputBox(Prompt:="Introduza o seu NOME:", _
Title:="Nome do Utilizador")
ActiveCell.FormulaR1C1 = UCase(ActiveCell)
Loop
Range("B65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = msg
End
End Sub
Resultado:
O Código:
Sub Auto_Open()
Dim Ops(1 To 5) As String
Dim msg As String
Ops(1) = Day(Date)
Ops(2) = Month(Date)
Ops(3) = Year(Date)
Ops(4) = Hour(Time)
Ops(5) = Minute(Time)
msg = Ops(3) & "-" & Ops(2) & "-" & Ops(1) & " " & Ops(4) & ":" & Ops(5)
Sheets("Sheet1").Select
Range("A65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Application.Cursor = xlNormal
Do While IsEmpty(ActiveCell)
ActiveCell.FormulaR1C1 = InputBox(Prompt:="Introduza o seu NOME:", _
Title:="Nome do Utilizador")
ActiveCell.FormulaR1C1 = UCase(ActiveCell)
Loop
Range("B65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = msg
End
End Sub