• Unable to run BAT file using VBA

    Author
    Topic
    #460496

    Hi,

    I have a friend who is trying to run a VBA macro which should run a bat file.

    The code below works:

    Code:
    Sub TestShell()
    
    	Dim RetVal
    
    	RetVal = Shell("C:WINDOWSsystem32CALC.EXE", 1)	' Run Calculator.
    
      End Sub

    But this fails on his windows vista/Office 2003 setup, where it used to work on a different system (don’t know the specs unfortunately):

    Code:
      Sub TestShellWithBAT()
    
    Dim RetVal
    
    ChDir ("C:Ftrade")
    
      RetVal = Shell("otherfunds.bat", 1)
    
      End Sub

    Any idea what gives?

    Viewing 5 reply threads
    Author
    Replies
    • #1164780

      What happens if you use

      RetVal = Shell(Environ(“comspec”) & ” /k “”otherfunds.bat”””, 1)

      or

      RetVal = Shell(Environ(“comspec”) & ” /k “”C:Ftradeotherfunds.bat”””, 1)

      This should leave the command window open so that you can view error messages, if any.

    • #1164793

      I’ll ask Hans, thanks.

    • #1164902

      Hi Hans,

      Nothing appears to happen in ether case.

      • #1164903

        It’s probably a security problem – you’d need to run the batch file as administrator, but I have no idea how to do that using Shell.

    • #1164921

      Maybe turning off UAC might help, I’ll suggest that.

    • #1165278

      No change yet, but the user reports he is using windows XP, not Vista.

      • #1165287

        Security isn’t likely to be a problem then. I’m sorry, I have no idea why it would fail.

    • #1165298

      We’re currently looking at comatibility mode, Seems to have an effect on the workings of parts of what the BAT file does. I’ll be dissecting the BAT file, shouldn’t be anything in there VBA can’t do I expect.

    Viewing 5 reply threads
    Reply To: Unable to run BAT file using VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: