Solved

How to use environment variables within Visual Basic and VBA

Posted on 2016-11-02
6
27 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 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
>>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
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:rayluvs
Comment Utility
Can u give an example?
0
 

Author Comment

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

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now