Registry


If a text string is too long, when you try to import it into the Registry it inserts a carriage return in the middle. If this happens it will not get added to the Registry.
You can drag the file into Notepad and remove the carriage return manually ??


HKEY_CLASSES_ROOT - Interface, OLE features
HKEY_CURRENT_USER - Data from the user's .dat file
HKEY_LOCAL_MACHINE - System specific settings
HKEY_USERS - Settings about all the users on the system.
HKEY_CURRENT_CONFIG - Hardware information


When is the Registry Updated ?

The Registry is only read once when the application starts up and once when the application is closed.
If the application crashes the Registry will not be updated and therefore any settings that have been changed will not be saved.



GetSetting and SaveSetting Functions

Rather than using the Windows API functions you can use the GetSetting and SetSetting functions.
It is important to remember that these functions only work with the following key name:

HKEY_CURRENT_USER\Software\VB and VBA Program Settings\ 


Call SaveSetting("Userform Positioning", ThisWorkbook.FullName & "-" & Me.Name, "Left", Me.Left") 
Call SaveSetting("Userform Positioning", ThisWorkbook.FullName & "-" & Me.Name, "Top", Me.Top")


VB and VBA Program Settings

This folder does not exist by default
You need to check that it exists before using it


Office 2013


Registry > Import
creates a .reg file


To edit an existing key, right click on it and select Rename from the opup menu
To create a new key click on the "parent" you want the new key to appear under click Edit > New > Key and type the name of the key
To create a new value choose the key it will belong to click Edit > New
Choose from
String Value
Bnary Value
DWORD value
type the name of the value and press Enter twice and fill in the value
to delete a key highlight it and press Edit > Delete


Excel graphs
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\Saskatchewan
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\Charting\AliasedDMToMetafilePlus
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\Charting\UseSystemGDI
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Legacy Rendering


HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options\DelayOleSrvParseDisplayName
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options\NoActivateOleLinkObjAtOpen


KB 2423462


Word - shortcut - linked worksheet object >> Update Link
Call was rejected by callee



Troubleshooting

Charts - Bug - Distorted Font Spacing
When you copy an Excel chart as a picture and then paste it into Word 2007, the font spacing gets distorted
This problem occurs when certain fonts are used in the chart.
KB - 970889

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\UsePrinterDCForMetafile 
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options\QFE_Boston

Registry Functions

DELETESETTINGSRemoves (or deletes) a key or section from the registry.
GETALLSETTINGSReturns the list of key settings and their values from the registry (Variant).
GETSETTINGReads from the registry and returns the value or key from the registry (String).
SAVESETTINGWrites to the registry and saves a section or key in the registry.

Nodes

Registry nodes for Excel 2013

The registry entries are only updated when Excel closes.
The following registry entry contains the list of recently used workbooks

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Recent Files\ 

The following registry entry contains the default number of worksheets in a new workbook.

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options\DefSheets 

Add-in Manager - Lists all the add-ins that are displayed in the (Tools > Add-ins) dialog box. Built-in add-ins that are included with Excel are not included in this list.
AddInLoadTimes -
DataRecommendation -
Error Checking -
File MRU - Stores the names of all the files last saved. Up to a maximum of 9.
Options - Holds a wide variety of setttings including the folder paths of any files that are to opened automatically when Excel starts.
Place MRU -
Recent Templates -
Resiliency -
Security -
Spell Checker - Stores information about your spelling checker options.
StatusBar -
User MRU -
Web Extension User MRU -


Reading & Writing


Private Declare Function RegOpenKeyA Lib "ADVAPI32.DLL" _ 
    (ByVal hKey As Long, ByVal sSubKey As String, _
    ByRef hkeyResult As Long) As Long

Private Declare Function RegCloseKey Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long) As Long

Private Declare Function RegSetValueExA Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long, ByVal sValueName As String, _
    ByVal dwReserved As Long, ByVal dwType As Long, _
    ByVal sValue As String, ByVal dwSize As Long) As Long

Private Declare Function RegCreateKeyA Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long, ByVal sSubKey As String, _
    ByRef hkeyResult As Long) As Long

Private Declare Function RegQueryValueExA Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long, ByVal sValueName As String, _
    ByVal dwReserved As Long, ByRef lValueType As Long, _
    ByVal sValue As String, ByRef lResultLen As Long) As Long

Sub UpdateRegistryWithTime() 
    RootKey = "hkey_current_user"
    Path = "software\microsoft\office\9.0\excel\LastStarted"
    RegEntry = "DateTime"
    RegVal = Now()
    LastTime = GetRegistry(RootKey, Path, RegEntry)
    Select Case LastTime
        Case "Not Found"
            Msg = "This routine has not been executed before."
        Case Else
            Msg = "This routine was lasted executed: " & LastTime
    End Select
    Msg = Msg & Chr(13) & Chr(13)
    
    Select Case WriteRegistry(RootKey, Path, RegEntry, RegVal)
        Case True
            Msg = Msg & "The registry has been updated with the current date and time."
        Case False
            Msg = Msg & "An error occured writing to the registry..."
    End Select
    MsgBox Msg, vbInformation, "Registry Demo"
End Sub

Private Function GetRegistry(Key, Path, ByVal ValueName As String) 
' Reads a value from the Windows Registry

    Dim hKey As Long
    Dim lValueType As Long
    Dim sResult As String
    Dim lResultLen As Long
    Dim ResultLen As Long
    Dim x, TheKey As Long

    TheKey = -99
    Select Case UCase(Key)
        Case "HKEY_CLASSES_ROOT": TheKey = &H80000000
        Case "HKEY_CURRENT_USER": TheKey = &H80000001
        Case "HKEY_LOCAL_MACHINE": TheKey = &H80000002
        Case "HKEY_USERS": TheKey = &H80000003
        Case "HKEY_CURRENT_CONFIG": TheKey = &H80000004
        Case "HKEY_DYN_DATA": TheKey = &H80000005
    End Select
    
' Exit if key is not found
    If TheKey = -99 Then
        GetRegistry = "Not Found"
        Exit Function
    End If

    If RegOpenKeyA(TheKey, Path, hKey) <> 0 Then _
        x = RegCreateKeyA(TheKey, Path, hKey)
    
    sResult = Space(100)
    lResultLen = 100
    
    x = RegQueryValueExA(hKey, ValueName, 0, lValueType, _
    sResult, lResultLen)
        
    Select Case x
        Case 0: GetRegistry = Left(sResult, lResultLen - 1)
        Case Else: GetRegistry = "Not Found"
    End Select
    
    RegCloseKey hKey
End Function

Private Function WriteRegistry(ByVal Key As String, _ 
    ByVal Path As String, ByVal entry As String, _
    ByVal value As String)
    
    Dim hKey As Long
    Dim lValueType As Long
    Dim sResult As String
    Dim lResultLen As Long
   
    TheKey = -99
    Select Case UCase(Key)
        Case "HKEY_CLASSES_ROOT": TheKey = &H80000000
        Case "HKEY_CURRENT_USER": TheKey = &H80000001
        Case "HKEY_LOCAL_MACHINE": TheKey = &H80000002
        Case "HKEY_USERS": TheKey = &H80000003
        Case "HKEY_CURRENT_CONFIG": TheKey = &H80000004
        Case "HKEY_DYN_DATA": TheKey = &H80000005
    End Select
    
' Exit if key is not found
    If TheKey = -99 Then
        WriteRegistry = False
        Exit Function
    End If

' Make sure key exists
    If RegOpenKeyA(TheKey, Path, hKey) <> 0 Then
        x = RegCreateKeyA(TheKey, Path, hKey)
    End If

    x = RegSetValueExA(hKey, entry, 0, 1, value, Len(value) + 1)
    If x = 0 Then WriteRegistry = True Else WriteRegistry = False
End Function

Sub TestIt() 
    RootKey = "hkey_current_user"
    Path = "software\microsoft\office\9.0\common\autocorrect"
    RegEntry = "path"
    MsgBox GetRegistry(RootKey, Path, RegEntry), vbInformation, _
        Path & "\RegEntry"
End Sub



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext