How to add double quotes in a string literal

前端 未结 7 2059
孤街浪徒
孤街浪徒 2021-01-17 15:09

Example code:

Dim a As String
a = 1234,5678,9123

I want to add literal double quotes to the variable a

Expected Output

7条回答
  •  不要未来只要你来
    2021-01-17 15:46

    I used the Chr$(34) method, like this:

    Sub RunPython()
        Dim scriptName As String
        Dim stAppName As String
        scriptName = ActiveWorkbook.Path & "\aprPlotter.py"
        stAppName = "python.exe " & Chr$(34) & scriptName & Chr$(34)
        Debug.Print stAppName
        Call Shell(stAppName, vbHide)
    End Sub
    

    I was using the same path for the python script as the Excel Workbook, to keep it easier for the users. I monkeyed with the quotes for 45 minutes before I found this thread. When the paths are sourced from active working locations (especially ones with spaces in Windows), I think this is a preferred method. Hopefully, this will help someone else.

提交回复
热议问题