ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   WScript object not found (???) (https://www.excelbanter.com/excel-programming/271363-re-wscript-object-not-found.html)

Tom Ogilvy

WScript object not found (???)
 
How about

Sub aaaa_testscript()

Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Debug.Print WshSysEnv("LOGONSERVER")
End Sub

or

Sub aaaa_testscript()
Set WshShell = VBA.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Debug.Print WshSysEnv("LOGONSERVER")
End Sub

remove the Wscript from CreateObject.

Regards,
Tom Ogilvy

"Randall Arnold" wrote in message
...
I am using the following code in Windows Scripting Host (wsh) macro:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Wscript.Echo WshSysEnv("LOGONSERVER")

This displays the name of the DNS logon server. It works fine as a
standalone script. Now, I need this to run in an Excel 2003 VBA module so

I
modified the code as follows:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
debug.print WshSysEnv("LOGONSERVER")

After running the macro, I received an "Object not found" error.

According
to WSH docs, no reference is needed, but I added one anyway and re-ran the
macro-- same result. Excel VBA claims that the WScript object is not
instantiated, it seems. However, WSH starts as a part of the OS so it
*should* be there. The fact that the script runs fine but the VBA version
doesn't has me mystified. I'm wondering if it's a bug in the Excel 2003
beta.

Anyone have any clues?

Randall Arnold





Randall Arnold[_2_]

WScript object not found (???)
 
D'oh!

Thanks Tom. Man, I'm an idiot. I should have known that!

-Randy

"Tom Ogilvy" wrote in message
...
How about

Sub aaaa_testscript()

Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Debug.Print WshSysEnv("LOGONSERVER")
End Sub

or

Sub aaaa_testscript()
Set WshShell = VBA.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Debug.Print WshSysEnv("LOGONSERVER")
End Sub

remove the Wscript from CreateObject.

Regards,
Tom Ogilvy

"Randall Arnold" wrote in message
...
I am using the following code in Windows Scripting Host (wsh) macro:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Wscript.Echo WshSysEnv("LOGONSERVER")

This displays the name of the DNS logon server. It works fine as a
standalone script. Now, I need this to run in an Excel 2003 VBA module

so
I
modified the code as follows:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
debug.print WshSysEnv("LOGONSERVER")

After running the macro, I received an "Object not found" error.

According
to WSH docs, no reference is needed, but I added one anyway and re-ran

the
macro-- same result. Excel VBA claims that the WScript object is not
instantiated, it seems. However, WSH starts as a part of the OS so it
*should* be there. The fact that the script runs fine but the VBA

version
doesn't has me mystified. I'm wondering if it's a bug in the Excel 2003
beta.

Anyone have any clues?

Randall Arnold








All times are GMT +1. The time now is 08:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com