Results 1 to 9 of 9
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:\WINDOWS\system32\CALC.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?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    What happens if you use

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

    or

    RetVal = Shell(Environ("comspec") & " /k ""C:\Ftrade\otherfunds.bat""", 1)

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

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll ask Hans, thanks.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Hans,

    Nothing appears to happen in ether case.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe turning off UAC might help, I'll suggest that.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No change yet, but the user reports he is using windows XP, not Vista.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Security isn't likely to be a problem then. I'm sorry, I have no idea why it would fail.

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •