MapMan
MapMan

Reputation: 668

Passing in multiple arguments in VBA to run a Python script

I have a very simple VBA script that will run a Python script, which has arguments specified (which are folder paths, that contain spaces).

Code is below

Dim path As String
path = Left(pdocinfo.path, InStrRev(pdocinfo.path, "\")) ' e.g C:\Temp\City Addresses

Dim pyLocation As String
pyLocation = "C:\Temp\filePath.py"

Dim strReports As String
strReports = path & "Reports\"

Dim strImages As String
strImages = path & "Images\"
Dim shellvar As Long
shellvar = shell("C:\Python26\ArcGIS10.0\python.exe " & pyLocation & " " & path & " " & strImages & " " & strReports , vbNormalFocus)

However, when the Python script is run, the file paths (strImages, strReports and path) do not get parsed in correctly because they contain spaces within the folder path.

What's the correct way for Python to interpret multiple arguments that are dynamic variables which also contain spaces?

Edit: I have tried the following, following on from the comment below

shellvar = Shell("C:\Python27\ArcGIS10.2\python.exe " & pyLocation & " " & """" & path & """" & " " & """" & strImages & """" & " " & """" & strReports & """", vbNormalFocus)

the result from the python script is enter image description here

The result I would like is

Argument 0: C:\Temp\filePath.py
Argument 1: "C:\Temp\City Addresses"
Argument 2: "C:\Temp\City Addresses\Images"
Argument 3: "C:\Temp\City Addresses\Reports"

Upvotes: 0

Views: 9362

Answers (1)

MatthewD
MatthewD

Reputation: 6761

Surround those with double quotes.

shellvar = shell("C:\Python26\ArcGIS10.0\python.exe " & pyLocation & " " & """" & path & """" & " " & """" & strImages & """" & " " & """" & strReports & """", vbNormalFocus)

Upvotes: 2

Related Questions