-
Aug 21st, 2013, 07:52 PM
#1
Thread Starter
New Member
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
Last edited by gjohn282; Aug 21st, 2013 at 07:58 PM.
-
Aug 21st, 2013, 09:16 PM
#2
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" )
-
Aug 21st, 2013, 09:17 PM
#3
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.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Aug 22nd, 2013, 12:41 AM
#4
Re: Conver VBA to VBscript - Environ("Temp") problem
Thread moved to the VBScript forum.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|