Conver VBA to VBscript - Environ("Temp") problem
I'm trying to covert some VBA code into VBscript. I borrowed the below code from a working VBA macro. This is not the entire code, but just the part that is giving me issues.
Error Message:
Thanks for any help!
Code:
strtempfile = Environ("TEMP") & Format(Now(), "yyyymmddhhnnss") & ".htm"
Set objrange = objdoc.Range(Start:= 0, End:= 0)
CreateTextFile strtempfile, strBody
objrange.InsertFile strtempfile, , , False, False
Kill strtempfile
Re: Conver VBA to VBscript - Environ("Temp") problem
This is VB6 section of these forums, but anyways
Try
Code:
Dim wshShell
Set wshShell = CreateObject( "WScript.Shell" )
Set wshSystemEnv = wshShell.Environment( "TEMP" )
Or
Code:
Dim wshShell
Set wshShell = CreateObject( "WScript.Shell" )
WScript.Echo wshShell.ExpandEnvironmentStrings( "TEMP" )
Re: Conver VBA to VBscript - Environ("Temp") problem
In VBScript, there is no Environ function. However, you can retrieve the %TEMP% environment variable either through the Environment property of the WshShell object or via the GetSpecialFolder method of the FileSystemObject object.
Again, VBScript has no Format function but it does have the FormatDateTime function.
Named arguments (Start:=0, End:=0) unfortunately aren't supported in VBScript.
The Kill statement isn't available in VBScript. Use either the Delete method of the File object or the DeleteFile method of the FileSystemObject.
Lastly, please refer to the Visual Basic for Applications Features Not In VBScript.
Re: Conver VBA to VBscript - Environ("Temp") problem
Thread moved to the VBScript forum.