Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Los Angeles
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    privateprofilestring (VBA6/Word2000/Outlook2000)

    I am trying to read Outlook's master category list from the registry while in a Word macro (finding Contacts). I am able to do this using
    privateprofilestring ("", "HKEY_CURRENT_USERSoftwareMicrosoftOffice9.0Outloo kCategories", "MasterList").

    But once the string is over 255 characters, I get a zero length string. I have been trying to understand the API function getprivateprofilestring, but do not understand how I use it. Is there a way to get a string out of a registry entry that is greater than 255 characters?

    Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: privateprofilestring (VBA6/Word2000/Outlook2000)

    The following code will read registry strings up to 1023 characters long. If you need even longer strings, modify the single occurrence of 1024 in the code to be one more than the maximum length you expect.

    Public Const REG_SZ = 1
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const KEY_QUERY_VALUE = &H1

    Declare Function RegCloseKey Lib "advapi32.dll" _
    (ByVal hKey As Long) As Long

    Declare Function RegOpenKeyEx Lib "advapi32.dll" _
    Alias "RegOpenKeyExA" _
    (ByVal hKey As Long, _
    ByVal lpSubKey As String, _
    ByVal ulOptions As Long, _
    ByVal samDesired As Long, _
    phkResult As Long) As Long

    Declare Function RegQueryValueEx Lib "advapi32.dll" _
    Alias "RegQueryValueExA" _
    (ByVal hKey As Long, _
    ByVal lpValueName As String, _
    ByVal lpReserved As Long, _
    lpType As Long, lpData As Any, _
    lpcbData As Long) As Long

    Function ReadString _
    (RootKey As Long, KeyName As String, ValueName As String) As String
    Dim lngKey As Long
    Dim strRes As String
    Dim intPos As Integer
    Dim lngBytes As Long
    Dim lngType As Long

    If RegOpenKeyEx _
    (RootKey, KeyName, 0, KEY_QUERY_VALUE, lngKey) = 0 Then
    strRes = String(1024, 0)
    lngBytes = Len(strRes)
    If RegQueryValueEx _
    (lngKey, ValueName, 0, lngType, ByVal strRes, lngBytes) = 0 Then
    If lngType = REG_SZ Then
    ReadString = Left(strRes, lngBytes - 1)
    End If
    End If
    RegCloseKey lngKey
    End If
    End Function

    Example:

    Dim strMasterList As String
    strMasterList = ReadString(HKEY_CURRENT_USER, _
    "SoftwareMicrosoftOffice9.0OutlookCategories", "MasterList")

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Los Angeles
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: privateprofilestring (VBA6/Word2000/Outlook2000)

    Hans

    Thanks! This works perfectly in Word 2000.

    In Word XP the registry key value is now BINARY. Is there any way to adjust for this?

    Thanks,

    David

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: privateprofilestring (VBA6/Word2000/Outlook2000)

    What would you like to do with a binary registry value? If you really have to inspect it, use RegEdit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •