Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Environ won't even compile

0

I can use the environ function from the immidiate window, but it won't even compile in Excel VBA. Is there a prereq or something I have missed?

Answer
Discuss

Answers

0

Well, found it, for some reason one need to do it like this: VBA.Environ("UserName").

Not just Environ("UserName") which I think will work in many cases.

Discuss

Discussion

Hi  Bjotr and welcome to the Forum.

Interesting. Both Environ("UserName") and VBA.Environ("Username") work for me (in both a macro and VB Explorer's Immediate Window) but typing  VBA.E offers Environ and the other various methods etc. / autocomplete options. 
John_Ru (rep: 3222) Apr 4, '22 at 7:57 am
Well, yes it should work. Copyed some code from MS Excel which using the Environ("username"). Dosen't compile. I think there is some option that I did not select or set.
Bjotr (rep: 2) Apr 4, '22 at 2:05 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login