'--------------------------------------------------------
' A mettre dans un module
'--------------------------------------------------------
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function LaMachineSeNomme() As String
Dim strBuffer As String * 255, strRetour As String
Dim lgLong As Long
On Error GoTo Plouf
strRetour = "J'en sais rien"
lgLong = GetComputerName(strBuffer, 255)
lgLong = InStr(1, strBuffer, Chr(0))
If lgLong > 0 Then strRetour = Left(strBuffer, lgLong - 1)
Plouf:
On Error GoTo 0
LaMachineSeNomme = strRetour
End Function
'------------------------
' Utilisation
'------------------------
Private Sub Workbook_Open()
With Sheets("Feuil1")
.Range("A1").Value = LaMachineSeNomme()
.DrawingObjects("CommandButton1").Enabled = .Range("A1").Value = "MaStation" '
End With
End Sub