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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript works as .vbs, won't work in VBA module

Status
Not open for further replies.

TropicalFred

Technical User
Jun 16, 2003
20
US
I have a VBScript that runs fine when I save it as a .vbs file, but when I put it into an Excel VBA module and try to run it I get a VB "Object Required" error on the first line. What am I doing wrong?

VBS code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("System")
WScript.Echo objEnv("OS")

VBA Code:
Sub vbs_test1()

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("System")
WScript.Echo objEnv("OS")

End Sub
 
Replace this:
Set WshShell = WScript.CreateObject("WScript.Shell")
By this:
Set WshShell = CreateObject("WScript.Shell")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Tried it and now I get the "Object Required" error on line 3. I also moved it to another machine and got the same results. I am using Office 2000 and Win 2000 Pro. If you think of anything else, let me know. Thanks.
 
Make sure you have a reference to teh windows scripting runtime library.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Replace this:
WScript.Echo objEnv("OS")
By this:
MsgBox objEnv("OS")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top