Solved

How to use environment variables within Visual Basic and VBA

Posted on 2016-11-02
6
215 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
[X]
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
  • 3
  • 3
6 Comments
 
LVL 52

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 52

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
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 

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 52

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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