PDA

View Full Version : Run Autoit File from Excel File Location



afzalw
04-21-2013, 03:06 PM
I am using this code and it gives me
Run time Error 5
Invalid Procedure or Argument

when I change last line to

runscript = Shell("FileName", 1)

It gives Run time Error 53
What am I doing wrong


Sub RunFileName()
Dim runscript
Dim FileName As String
FileName = ThisWorkbook.Path & "\AutoitCode.au3"
MsgBox (FileName)
runscript = Shell(FileName, 1)
End Sub

SamT
04-21-2013, 05:45 PM
AutoitCode.au3 does not look like an executable file. If it's not, VBA willl give a run time error 5.

You can try Adding the executable that runs *.au3 files to the path name. This line assume that AutoIt.exe is in the System Path

FileName = "AutoIt3.exe " & ThisWorkbook.Path & "\AutoitCode.au3"

Note the space after AutoIt.exe

If it's not, you'll have to find its path and
Dim AutoItPath
AutoItPath = "Path to Executable" & "\AutoIt.exe "
runscript = Shell(AotuItPath &FileName, 1)
Note the space after AutoIt.exe

Kenneth Hobs
04-22-2013, 07:23 AM
You might want to use DIR() to see if the files exists first, otherwise:Sub RunFileName()
Dim runscript
Dim FileName As String FileName = ThisWorkbook.Path & "\AutoitCode.au3"
MsgBox (FileName)
runscript = Shell("cmd /c " & """" & FileName & """", 1)
End Sub

Of course if AutoIt is not installed, it will fail as well. There are ways to find that out if needed.

mdmackillop
04-23-2013, 04:58 AM
You could also try FollowHyperlink