我有以下一段VB代码来获取注册表子项(不是注册表的键或值).我只需要在Microsoft子键中列出应用程序(例如Office,记事本,键盘等).
它曾在VB.NET,但我想同样的代码适用于VBA中宏,我说弄一个运行时错误"Object variable or With block variable not set"上线GetOBject和EmumKey.我虽然以下代码应兼容VB.NET和VBA.有人可以解释一下吗?
Dim temp As Object
'On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
temp = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\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
Run Code Online (Sandbox Code Playgroud)
bre*_*tdj 12
对于VBA,请尝试这样
temp 是一个对象,需要与Set一起使用temp.Enum语法是temp.EnumKey HKEY_CURRENT_USER, rPath, arrSubKeys不是temp.EnumKey(HKEY_CURRENT_USER, rPath, arrSubKeys)Dim 你的代码顶部的变量是否整洁:)此代码列出HKEY_CURRENT_USER\Software\Microsoft\了VBE的立即窗口下的所有文件夹
Const HKEY_CURRENT_USER = &H80000001
Sub TestME()
Dim temp As Object
Dim strComputer As String
Dim rPath As String
Dim arrSubKeys()
Dim strAsk
strComputer = "."
Set temp = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
rPath = "Software\Microsoft\"
temp.EnumKey HKEY_CURRENT_USER, rPath, arrSubKeys
For Each strAsk In arrSubKeys
Debug.Print strAsk
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
