title: Read registry subkeys from VBA
body: <p>I have the following piece of VB code to get the registry subkey (<strong>NOT</strong> the key or the value of a registry). I just need to list out applications in Microsoft subkey (e.g. Office, Notepad, Keyboard etc.). </p>
  
  <p>It worked in <strong>VB.NET</strong> but I'm trying to apply the same code to <strong>VBA</strong> in Macro, I get a run time error saying <code>"Object variable or With block variable not set"</code> on the line of <code>GetOBject</code> and <code>EmumKey</code>. I though the following code should be compatible for both <strong>VB.NET</strong> and <strong>VBA</strong>. 
  Can anyone please explain? </p>
  
  <pre><code>Dim temp As Object
  'On Error Resume Next
  Const HKEY_CURRENT_USER = &amp;H80000001
  temp = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; "." &amp; "\root\default:StdRegProv")
  
  Dim rPath As String
  rPath = "Software\Microsoft\IdentityCRL\UserExtendedProperties"
  
  Dim arrSubKeys(5) As Object
  temp.EnumKey(HKEY_CURRENT_USER, rPath, arrSubKeys)
  
  For Each ask In arrSubKeys
      MsgBox(ask.ToString)
  Next
  </code></pre>