Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to use environment variables within Visual Basic and VBA

Posted on 2016-11-02
6
101 Views
Last Modified: 2016-11-03
We have a Microsoft application that has VBA functionality. We also have application made in Visual Basic 6. What we would like to know is if we can use some sort of Windows environment variable to pass values between the VBA environment and the VBA environment.
0
Comment
Question by:rayluvs
  • 3
  • 3
6 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41870451
>>Windows environment variable
try use Environfunction or using Windows APIs

For Environ function:
http://codevba.com/office/environ.htm#.WBoATMloOtY
https://www.techonthenet.com/excel/formulas/environ.php
0
 

Author Comment

by:rayluvs
ID: 41870470
Sorry about that.  We think we set the question wrong.   We already use environments variable like user profile, name, computer, etc.  What we are looking for is how to use an environment variable  or create one to give it a value within VBA and pass it to VB6 application and vice a versa.

Is there a way to go about it?
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 41870498
environment variables are system defined. hence, if you want to define your own variable, it would be categorized as custom variables.

I don't think existing VBA libraries will allow you to amend its own functions (including Environ function), or at least I never heard about this.

What we are looking for is how to use an environment variable  or create one to give it a value within VBA and pass it to VB6 application and vice a versa.
you can simply use a self-defined setting file instead.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:rayluvs
ID: 41870828
Can u give an example?
0
 

Author Comment

by:rayluvs
ID: 41870939
Question, how about using "User Variables" in Advance section of computer properties? (how would that work? )
0
 
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
ID: 41871482
Can u give an example?

Read INI File in VBA
http://dailydoseofexcel.com/archives/2011/04/19/read-ini-file-in-vba/

Question, how about using "User Variables" in Advance section of computer properties? (how would that work? )
you may try to use SetEnvironmentVariable and GetEnvironmentVariable APIs

GetEnvironmentVariable-Function
http://www.vbarchiv.net/api/api_getenvironmentvariable.html
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Being an active EE Expert means to get a lot of (E)EMail, as you certainly know. If you are using Outlook, I'll show you how to minimize your inbox contents without losing anything – even improve the experience by changing the Subject line to facili…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question