You use the WhatsApp function - and the routine it's calling and declarations in a module. Save and compile. If all the references have been resolved and if it compiles, you're ready to use the WhatsApp function in a forms or modules VBA code, just like you would any built-in function. You've simply added a new function to VBA.
I'm including the entire module - everything you need, but this is just one of several registry functions in the set. Be sure to let me know if you have any problems compiling it and specifically what is missing. My own WhatsApp(".mdb") returns: "C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE". Office 2010 will be OFFICE14, not "OFFICE11".
If for some reason, someone is using Access 64-bit version, this needs to be modified to use the 64-bit Windows API.
CODE
Option Compare Database
Option Explicit
Public Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Public Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE + KEY_CREATE_SUB_KEY + KEY_ENUMERATE_SUB_KEYS + KEY_NOTIFY + KEY_CREATE_LINK + READ_CONTROL
' Reg Key ROOT Types...
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const ERROR_SUCCESS = 0 ' Return Value...
Public Const REG_SZ = 1 ' Unicode nul terminated string
Public Const REG_DWORD = 4 ' 32-bit number
Public Function WhatsApp(ByVal Ext As String) As String
Dim V As String
Dim i As Integer
If Not GetKeyValue(HKEY_CLASSES_ROOT, Ext, "", V) Then
MsgBox "No value for " & Ext & ", Exiting"
Exit Function
End If
If Not GetKeyValue(HKEY_CLASSES_ROOT, V & "\shell\open\command", "", V) Then
MsgBox "No value for " & Ext & ", Exiting"
Exit Function
End If
i = InStr(1, V, ".exe" & Chr(34))
WhatsApp = Mid(V, 1, i + 5)
End Function
Public Function GetKeyValue(KeyRoot As Long, KeyName As String, SubKeyRef As String, ByRef KeyVal As String) As Boolean
' **********************************************
Dim i As Long , rc As Long, hKey As Long, hDepth As Long, KeyValType As Long, tmpVal As String, KeyValSize As Long
' ********************************************
rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey) ' Open Registry Key
If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError ' Handle Error...
tmpVal = String$(1024, 0) ' Allocate Variable Space
KeyValSize = 1024 ' Mark Variable Size
' Retrieve Registry Key Value...
'------------------------------------------------------------
rc = RegQueryValueEx(hKey, SubKeyRef, 0, KeyValType, tmpVal, KeyValSize) ' Get/Create Key Value
If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError ' Handle Errors
If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then ' Win95 Adds Null Terminated String...
tmpVal = Left(tmpVal, KeyValSize - 1) ' Null Found, Extract From String
Else ' WinNT Does NOT Null Terminate String...
tmpVal = Left(tmpVal, KeyValSize) ' Null Not Found, Extract String Only
End If
' Determine Key Value Type For Conversion...
'------------------------------------------------------------
Select Case KeyValType ' Search Data Types...
Case REG_SZ ' String Registry Key Data Type
KeyVal = tmpVal ' Copy String Value
Case REG_DWORD ' Double Word Registry Key Data Type
For i = Len(tmpVal) To 1 Step -1 ' Convert Each Bit
KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1))) ' Build Value Char. By Char.
Next
KeyVal = Format$("&h" + KeyVal) ' Convert Double Word To String
End Select
GetKeyValue = True ' Return Success
rc = RegCloseKey(hKey) ' Close Registry Key
Exit Function ' Exit
GetKeyError: ' Cleanup After An Error Has Occured...
'------------------------------------------------------------
KeyVal = "" ' Set Return Val To Empty String
GetKeyValue = False ' Return Failure
rc = RegCloseKey(hKey) ' Close Registry Key
'------------------------------------------------------------
End Function