• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using API Calls

As far as your other code is concerned, there’s no difference between a procedure declared in VBA (using the Sub or Function keywords) and one declared using the Declare keyword. Here’s a VBA function that gets the computer name using the API call just declared:

Function GetThisComputerName() As String
  ' Retrieve the name of this computer using
  ' the Windows API
  Dim strName As String
  Dim lngChars As Long
  Dim lngRet As Long

  strName = Space(255)
  lngChars = 255

  lngRet = GetComputerName(strName, lngChars - 1)
  If lngChars > 0 Then
    GetThisComputerName = Left(strName, lngChars)
  Else
    GetThisComputerName = "Unable to retrieve name."
  End If
End Function


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint