Creating a Windows DLL with Visual Basic
Subject:   DLL works in VB exe but not in VBA
Date:   2005-11-22 06:12:37
From:   mike2508
I created the following function within a dll, for getting the value of a key in the registry, for an excel add-in my company uses (I had to use this method for reading the registry because our IT dept has restricted access to the registry for users, and therefore neither windows registry API calls, nor the use of "WScript.Shell" work) :

Public Function GetLastUserName() As String

Const HKEY_CURRENT_USER = &H80000001
Dim objReg As Object
Dim strValue As String, strKeyPath As String, strComputer As String

On Error GoTo EndGetUserFunction

strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "The registry path to the key"

objReg.GetStringValue HKEY_CURRENT_USER, strKeyPath, "User", strValue
GetLastUserName = StrConv(strValue, vbFromUnicode)

Set objReg = Nothing

End Function

The DLL works ok if I use it in a visual basic exe, but when I try to use it in Excel VBA, Excel crashes. I dont know why

How can I resolve this issue?


1 to 1 of 1
  1. DLL works in VB exe but not in VBA
    2006-01-17 22:44:12  mandanaL [View]

    • DLL works in VB exe but not in VBA
      2007-08-28 02:31:35  Lukie [View]

1 to 1 of 1