首页 > 解决方案 > 如何定义文件 .exe 读取的多个参数?

问题描述

我想在 Excel 中添加几个参数以供 .exe 文件(python 脚本)读取。我在 VBA 中使用了这两个主要功能。有谁知道我可以如何更改它们以允许合并多个参数?我只能在“module_type”中插入一个参数。

非常感谢你的帮助!

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.")

结束子

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

结束子

标签: pythonarraysvbaparametersexe

解决方案


推荐阅读