Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use environment variables within Visual Basic and VBA

Posted on 2016-11-02
6
Medium Priority
?
293 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 53

Accepted Solution

by:
Ryan Chong earned 2000 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 53

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
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.

 

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 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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