
Premetto che non sò nulla di excel, mi è stato chiesto di creare una macro per recuperare il nome del pc da dove il foglio excel viene aperto, qualcuno di voi può aiutarmi nell'impresa?
Grazie a tutti anticipatamente

Moderatori: Anthony47, Flash30005
Private Declare Function api_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function api_GetComputerName Lib "Kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function CNames(UserOrComputer As Byte) As String
'UserorComputer; 1=User, anything else = computer
Dim NBuffer As String
Dim Buffsize As Long
Dim wOK As Long
Buffsize = 256
NBuffer = Space$(Buffsize)
If UserOrComputer = 1 Then
wOK = api_GetUserName(NBuffer, Buffsize)
CNames = Trim$(NBuffer)
Else
wOK = api_GetComputerName(NBuffer, Buffsize)
CNames = Trim$(NBuffer)
End If
End Function
Sub StampaDati()
stringa = "Computer " & CNames(2)
MsgBox (stringa)
stringa = " in uso da parte di " & CNames(1)
MsgBox (stringa)
End Sub
Private Declare Function api_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function api_GetComputerName Lib "Kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub StampaDati()
Dim NBuffer As String
Dim Buffsize As Long
Dim wOK As Long
Buffsize = 256
NBuffer = Space$(Buffsize)
wOK = api_GetUserName(NBuffer, Buffsize)
Utente = Trim$(NBuffer)
wOK = api_GetComputerName(NBuffer, Buffsize)
computer = Trim$(NBuffer)
computer = Left$(computer, Len(computer) - 3) ' Elimina ultimi caratteri (danno fastidio a msgbox)
MsgBox ("Computer '" & computer & "' in uso da parte di '" & Utente & "'")
End Sub
Roberto183 ha scritto:Anch'io ho provato a cercare con google, ma non è così semplice
Torna a Applicazioni Office Windows
confrontare e evidenziare 2 fogli excel Autore: niccia |
Forum: Applicazioni Office Windows Risposte: 5 |
[EXCEL] controllo corrispondenza tra valori con un vincolo Autore: sbs |
Forum: Applicazioni Office Windows Risposte: 9 |
Macro per aprire file salvato su sharepoint Onedrive Autore: marcopont |
Forum: Applicazioni Office Windows Risposte: 2 |
Visitano il forum: Nessuno e 94 ospiti