Conver VBA to VBscript - Environ("Temp") problem-VBForums
Results 1 to 4 of 4

Thread: Conver VBA to VBscript - Environ("Temp") problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    10

    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:
    • Type mismatch 'Environ'


    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 08:58 PM.

  2. #2
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    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" )

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    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)

  4. #4
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Conver VBA to VBscript - Environ("Temp") problem

    Thread moved to the VBScript forum.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.