I would like to add several parameters in Excel to be read by an .exe file (python script). I have these two main functions in VBA that I am using for this. Does anyone know how I can change them to allow the incorporation of multiple parameters? I'm only able to insert one parameter in the 'module_type'.
Thank you so much for your help!
Thank you so much for your help!
VBA Code:
Public Sub Import_data(ByVal title As String, ByVal python_script As String, ByVal table_name As String, ByVal procedure_name As String, Optional update_log As Boolean = False, Optional module_type As String, Optional get_file As Boolean = True)
Dim mypath As String
MsgBox ("Starting to import " & title & " data")
'mypath = Application.GetOpenFilename(, , "Import executable file")
If get_file Then
MyFile = Application.GetOpenFilename(, , "Import " & title & " file")
If MyFile = "False" Then Exit Sub
End If
mypath = ThisWorkbook.Path
schemaName = get_schema()
If get_file Then
Call RunPythonScript(mypath, python_script, """" & module_type & """ """ & get_database() & """ """ & connection_string("python") & """ """ & schemaName & """ --file_path """ & MyFile & """ --table """ & table_name & """")
Else
Call RunPythonScript(mypath, python_script, """" & module_type & """ """ & get_database() & """ """ & connection_string("python") & """ """ & schemaName)
End If
Dim cnn As New ADODB.Connection
Dim ConnectionString As String
Dim str As String
Dim rst As New ADODB.Recordset
ConnectionString = connection_string()
cnn.Open ConnectionString
'Change myFile to include to exclude '
MyFile = Replace(MyFile, "'", "")
If procedure_name <> "" Then
If update_log Then
Call correrQuery("exec " & procedure_name & " '" & MyFile & "'")
Else
Call correrQuery("exec " & procedure_name)
End If
End If
MsgBox ("Imported " & title & " data successfully.")
Code:
Public Sub RunPythonScript(ByVal exe_path As String, ByVal exe_name As String, Optional ByVal params As String = "")
fullCmd = exe_name
If params <> "" Then
fullCmd = fullCmd & " " & params
End If
Debug.Print fullCmd
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.CurrentDirectory = exe_path
wsh.Run fullCmd, windowStyle, waitOnReturn