Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to read Office Product ID in VBA

Does anyone have an idea how to access the Office Product ID from VBA in Excel?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default How to read Office Product ID in VBA

not sure about office, but the following gets the excel data - i'm sure you
can adjust the path and get what you need.

Const MAX_STRING As Long = 128
Public Const REG_BINARY = 3&
Public Const REG_DWORD = 4&

Declare Function RegOpenKeyA Lib "ADVAPI32.DLL" _
(ByVal hkey As Long, _
ByVal sKey As String, _
ByRef plKeyReturn As Long) As Long

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

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

Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
'

Sub ShowExcelProductID()
MsgBox GetRegistryValue(HKEY_LOCAL_MACHINE, _
"Software\Microsoft\Microsoft Excel 97\97.2.0.0717(1033)\Registration",
"ProductID")
End Sub

Function GetRegistryValue(KEY As Long, SubKey As String, _
ValueName As String) As String
'Pass:
' (1) the KEY (e.g., HKEY_CLASSES_ROOT),
' (2) the SUBKEY (e.g., "Excel. Sheet.5"),
' (3) the value's name (e.g., "" [for default] Or "whatever")


Dim Buffer As String * MAX_STRING, ReturnCode As Long
Dim KeyHdlAddr As Long, ValueType As Long, ValueLen As Long
Dim TempBuffer As String, Counter As Integer
ValueLen = MAX_STRING
ReturnCode = RegOpenKeyA(KEY, SubKey, KeyHdlAddr)
If ReturnCode = 0 Then
ReturnCode = RegQueryValueExA(KeyHdlAddr, ValueName, _
0&, ValueType, Buffer, ValueLen)
RegCloseKey KeyHdlAddr
'If successful ValueType contains data type
' of value And ValueLen its length
If ReturnCode = 0 Then
Select Case ValueType
Case REG_BINARY
For Counter = 1 To ValueLen
TempBuffer = TempBuffer & _
Stretch(Hex(Asc(Mid(Buffer, Counter, 1)))) & " "
Next
GetRegistryValue = TempBuffer
Case REG_DWORD
TempBuffer = "0x"
For Counter = 4 To 1 Step -1
TempBuffer = TempBuffer & _
Stretch(Hex(Asc(Mid(Buffer, Counter, 1))))
Next
GetRegistryValue = TempBuffer
Case Else
GetRegistryValue = Buffer
End Select
Exit Function
End If
End If
GetRegistryValue = "Error"
End Function

Function Stretch(ByteStr As String) As String
If Len(ByteStr) = 1 Then ByteStr = "0" & ByteStr
Stretch = ByteStr
End Function



"Rhythm" wrote:

Does anyone have an idea how to access the Office Product ID from VBA in Excel?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating PDF No Longer Works in Any Office Product Mark Excel Discussion (Misc queries) 3 March 1st 10 01:13 AM
I need a product key for my Trail product, 2007 Microsoft Office s sltchsyi Setting up and Configuration of Excel 0 May 4th 09 01:32 AM
How to distribute Macros/write add-ins in Office product Neo[_4_] Excel Programming 4 January 11th 06 02:36 PM
HOW CAN I READ SPREADSHEETS CREATED BY OFFICE 2000 ON OFFICE 2003. BOLOMO3 Excel Worksheet Functions 1 March 31st 05 01:40 AM
How do I open a .wks file (worksheet) in an Office XP product? judanl Excel Discussion (Misc queries) 1 February 19th 05 04:49 PM


All times are GMT +1. The time now is 09:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"