Windows 7 - Environ$ not working in vba - Asked By Glenna Reinhardt on 30-Mar-12 10:12 AM

We are switching over to Windows 7.  I have a line of code in two different apps that is using Environ$ to get some data from an ini file.  In VB6 (yes, I did say VB6), the code works fine.  However, in VBA, I get a compile error, and it tells me the library is not found.  I know it is something simple that I'm not seeing.  Any ideas?  With vba, I'm using it in a word template to get user information stored in an ini file on their home drive.  Also, I want to add that this does work in our current environment.  It just doesn't work on Windows 7.
Devil Scorpio replied to Glenna Reinhardt on 30-Mar-12 02:12 PM
Hi,

Add this to a public [not a form] module if you are using Access 2003....

Public Function Environ(Expression)
On Error GoTo Err_Environ

Environ = VBA.Environ(Expression)

Exit_Environ:
Exit Function

Err_Environ:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Environ

End Function


Then call the variable Environ.
Glenna Reinhardt replied to Devil Scorpio on 30-Mar-12 02:22 PM
I'm not using access, but I will give this a try.  Thanks so much!  I think what the problem is that when they set up the Windows 7 Test machines for us to look at, they didn't install everything.  There is no reason this should not work in VBA, and it still works with vb6, but I will try what you sent.  I'm thinking a reference is missing.

Thanks!