Modifying VBA to work with 64bit Excel

Joshua Winbrook
Joshua Winbrook used Ask the Experts™
on
I had this question after viewing Nslookup in Excel.

I get an error saying this module doesn't work in my 64bit Excel for

Private Declare Function InternetGetConnectedState Lib "wininet.dll" ( _
      ByRef lpdwFlags As Long, _
      ByVal dwReserved As Long _
   ) As Long

Private Declare Function gethostbyname Lib "wsock32" ( _
      ByVal HostName As String _
   ) As Long

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
      ByRef Destination As Any, _
      ByRef Source As Any, _
      ByVal Length As Long _
   )

Public Declare Function WSAStartup Lib "wsock32" _
   (ByVal wVersionRequired As Long, _
    lpWSADATA As WSADATA) As Long
    
Public Declare Function WSACleanup Lib "wsock32" () As Long

Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long

Private Declare Function IcmpCloseHandle Lib "icmp.dll" ( _
      ByVal IcmpHandle As Long _
   ) As Long
   
Private Declare Function IcmpSendEcho Lib "icmp.dll" ( _
   ByVal IcmpHandle As Long, _
   ByVal DestinationAddress As Long, _
   ByVal RequestData As String, _
   ByVal RequestSize As Long, _
   ByVal RequestOptions As Long, _
   ReplyBuffer As ICMP_ECHO_REPLY, _
   ByVal ReplySize As Long, _
   ByVal Timeout As Long) As Long

Open in new window


What do I need to do to make it work?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
    #If Win64 Then
		Private Declare PtrSafe Function gethostbyname Lib "WSOCK32.DLL" (ByVal hostname As String) As Long
        Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (xDest As Any, xSource As Any, ByVal nbytes As Long)
        Private Declare PtrSafe Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long
        Private Declare PtrSafe Function WSACleanup Lib "WSOCK32.DLL" () As Long
        Public Declare PtrSafe Function IcmpCreateFile Lib "icmp.dll" () As Long
        Public Declare PtrSafe Function IcmpCloseHandle Lib "icmp.dll" (ByVal IcmpHandle As Long) As Long
        Private Declare PtrSafe Function IcmpSendEcho Lib "icmp.dll" _
           (ByVal IcmpHandle As Long, _
            ByVal DestinationAddress As Long, _
            ByVal RequestData As String, _
            ByVal RequestSize As Long, _
            ByVal RequestOptions As Long, _
            ReplyBuffer As ICMP_ECHO_REPLY, _
            ByVal ReplySize As Long, _
            ByVal Timeout As Long) As Long
    #Else
		Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal hostname As String) As Long
        Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (xDest As Any, xSource As Any, ByVal nbytes As Long)
        Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long
        Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
        Public Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
        Public Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal IcmpHandle As Long) As Long
        Private Declare Function IcmpSendEcho Lib "icmp.dll" _
           (ByVal IcmpHandle As Long, _
            ByVal DestinationAddress As Long, _
            ByVal RequestData As String, _
            ByVal RequestSize As Long, _
            ByVal RequestOptions As Long, _
            ReplyBuffer As ICMP_ECHO_REPLY, _
            ByVal ReplySize As Long, _
            ByVal Timeout As Long) As Long
    #End If

Open in new window

Instead of #If Win64 you can also use #If VBA7
I don't see that you mentioned the GetStringFromIPAddress and GetIPAddressFromHostName functions anywhere in your question...
Without seeing the code there is no way we can debug it for you. Anyway, It should be asked in a new question as your initial question was answered.

Author

Commented:
Agreed, posted as a new question.  Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial