I'm writing a macro that needs to:
- Start .bat file
- Wait until .bat file is finished (data is downloaded from Oracle to .csv via SQLcl)
- Continue executing rest of VBA
I found two solutions for that problem:
First one - via Shell:
Dim shell_command As String
shell_command = ".bat_file_location"
Call Shell(shell_command, vbNormalFocus)
which opens the .bat file but the window immediately closes and nothing is executed.
Second one - via Windows Script Host Object:
Dim strCommand As String
Dim lngErrorCode As Long
Dim wsh As WshShell
Set wsh = New WshShell
strCommand = Chr(34) & _
".bat_file_location" & _
Chr(34)
lngErrorCode = wsh.Run(strCommand, _
WindowStyle:=0, _
waitonreturn:=True)
If lngErrorCode <> 0 Then
MsgBox "Uh oh! Something went wrong with .bat file!"
Exit Sub
End If
Set wsh = Nothing
this option does not work (lngErrorCode=0) and I don't quite know why. I use the same method for other .bat files which download data via BTEQ from Teradata database, so I'm assuming that SQLcl/Oracle database doesn't want to work with that method.
Do you have any ideas how to overcome this?
.bat file code:
sql user/password@//hostname:port/servicename @"path\code.sql"
Any advices will be much appreciated. Regards.