Solved

How to use environment variables within Visual Basic and VBA

Posted on 2016-11-02
6
155 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 51

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 51

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

 

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 51

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Database 5 45
Userform to just enter information that is refreneced to a cell 15 33
vba error next without for 3 15
Hash on Excel 13 40
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…
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.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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