Hello, Friends ...
I'm trying to create an Excel macro to delete from the list of recent documents only those not pinned, directly from registry (HKLM \ Software \ Microsoft \ Office \ 12.0 \ Excel \ File MRU), since I have not found another way to do it . I got some parts of the code on the internet and, after some changes, it looked like this:
Sub Clear_ExcelMRU()
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
MRU_PINNED = "F00000001"
MRU_UNPINNED = "F00000000"
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Office\12.0\Excel\File MRU"
objRegistry.EnumValues HKEY_CURRENT_USER, strKeyPath, arrValueNames, arrValueTypes
For I = 0 To UBound(arrValueNames)
strText = arrValueNames(I)
strValueName = arrValueNames(I)
strValReg = ""
Select Case arrValueTypes(I)
Case REG_SZ
objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strvalue
If Mid(strvalue, 2, 9) = MRU_PINNED Then
strText = strText & ": " & strvalue & Chr(13) & "MRU_PINNED"
ElseIf Mid(strvalue, 2, 9) = MRU_UNPINNED Then
strText = strText & ": " & strvalue & Chr(13) & "MRU_UNPINNED"
strValReg = "HKEY_CURRENT_USER\" & strKeyPath & "\" & strValueName
Kill strValReg
End If
Case REG_DWORD
objRegistry.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, intValue
strText = strText & ": " & intValue
Case REG_MULTI_SZ
objRegistry.GetMultiStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues
strText = strText & ": "
For Each strvalue In arrValues
strText = strText & " " & strvalue
Next
Case REG_EXPAND_SZ
objRegistry.GetExpandedStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strvalue
strText = strText & ": " & strvalue
Case REG_BINARY
objRegistry.GetBinaryValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues
strText = strText & ": "
For Each strvalue In arrValues
strText = strText & " " & strvalue
Next
End Select
MsgBox strText
Next
End Sub
But I am not able to delete the not pinned itens from registry by using the "Kill" statement in the first option of select case (Case REG_SZ).
What's wrong? Is there another way to do it?
Thanks.
I'm trying to create an Excel macro to delete from the list of recent documents only those not pinned, directly from registry (HKLM \ Software \ Microsoft \ Office \ 12.0 \ Excel \ File MRU), since I have not found another way to do it . I got some parts of the code on the internet and, after some changes, it looked like this:
Sub Clear_ExcelMRU()
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
MRU_PINNED = "F00000001"
MRU_UNPINNED = "F00000000"
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Office\12.0\Excel\File MRU"
objRegistry.EnumValues HKEY_CURRENT_USER, strKeyPath, arrValueNames, arrValueTypes
For I = 0 To UBound(arrValueNames)
strText = arrValueNames(I)
strValueName = arrValueNames(I)
strValReg = ""
Select Case arrValueTypes(I)
Case REG_SZ
objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strvalue
If Mid(strvalue, 2, 9) = MRU_PINNED Then
strText = strText & ": " & strvalue & Chr(13) & "MRU_PINNED"
ElseIf Mid(strvalue, 2, 9) = MRU_UNPINNED Then
strText = strText & ": " & strvalue & Chr(13) & "MRU_UNPINNED"
strValReg = "HKEY_CURRENT_USER\" & strKeyPath & "\" & strValueName
Kill strValReg
End If
Case REG_DWORD
objRegistry.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, intValue
strText = strText & ": " & intValue
Case REG_MULTI_SZ
objRegistry.GetMultiStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues
strText = strText & ": "
For Each strvalue In arrValues
strText = strText & " " & strvalue
Next
Case REG_EXPAND_SZ
objRegistry.GetExpandedStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strvalue
strText = strText & ": " & strvalue
Case REG_BINARY
objRegistry.GetBinaryValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues
strText = strText & ": "
For Each strvalue In arrValues
strText = strText & " " & strvalue
Next
End Select
MsgBox strText
Next
End Sub
But I am not able to delete the not pinned itens from registry by using the "Kill" statement in the first option of select case (Case REG_SZ).
What's wrong? Is there another way to do it?
Thanks.