Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB\VBA %systemroot% equivlant.

Status
Not open for further replies.

Turpis

Programmer
Apr 16, 2002
151
What is the VB equivlant to %systemroot%?



Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
Excuse my ignorance....

can you define %systemroot%?
 
Thanks Justin, do you happen to know what .dll or .ocx has Environ in it? For some reason a batch of new Dell's we got are missing the object or library associated with this command.

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
I think that "Environ" only works with NT - if you're not on NT, you may have problems - Please note, I can't test this 'cos I'm on NT so it works for me...

Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
ENVIRON( ) works fine in Excel 97.

The following references are in use:
Code:
  Visual Basic For Applications        VBA332.DLL
  Microsoft Excel 8.0 Object Library   EXCEL8.OLB
  Microsoft Forms 2.0 Object Library   FM20.DLL
 
Fair enough - I've never been able to test it being as I've been on NT since I started working - Just remembered someone on the Excel_L list saying that it didn't work except on NT

Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
The computers that it is not working on are WinXP, Office2000. Can't figure out the problem. My computer is WinXP, OfficeXPDeveloper so everything always works on my computer, which I guess sucks sometimes (like now).

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
works here on my Win XP SP-1 with Office 2002 SP-2

you could try the API to get environment variables:

Code:
Option Explicit

Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long

Function GetEnvironmentVar(sName As String) As String
    'KPD-Team 2000
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    GetEnvironmentVar = String(255, 0)
    GetEnvironmentVariable sName, GetEnvironmentVar, Len(GetEnvironmentVar)
    If InStr(1, GetEnvironmentVar, Chr$(0)) > 0 Then GetEnvironmentVar = Left$(GetEnvironmentVar, InStr(1, GetEnvironmentVar, Chr$(0)) - 1)
End Function

MsgBox GetEnvironmentVar("SystemRoot") & vbCrLf & GetEnvironmentVar("windir")

here are other API calls you could look at:

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top