0

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"
1
  • 1
    You are probably going to have to surround those with double quotes. & """" & strImages & """" & There are four double quotes to produce a single double quote. Commented Sep 1, 2015 at 15:54

1 Answer 1

2

Surround those with double quotes.

shellvar = shell("C:\Python26\ArcGIS10.0\python.exe " & pyLocation & " " & """" & path & """" & " " & """" & strImages & """" & " " & """" & strReports & """", vbNormalFocus)
Sign up to request clarification or add additional context in comments.

1 Comment

I've tried that but the parameters that are used within python is not correct. I've updated the questions to show your example as well as a screenshot of the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.