如何在VBA文本文件输出中包含空格

时间:2017-03-28 12:59:09

标签: excel vba excel-vba

如何在VBA中将空格作为输出的一部分?

我目前有以下代码:

 Select :P36_PRODUCT_LISTING,    
        LISTAGG(b.product_name, ', ') WITHIN GROUP (ORDER BY b.product_name)   OVER (PARTITION BY B.SALES_ORDER_NUMBER) AS products,
    ...
from ORDER o join
     PRODUCTS_BOUGHT B
     on p.SALES_ORDER_NUMBER = B.SALES_ORDER_NUMBER
    where (:P36_PRODUCT_LISTING = 'All' or
           o.SALES_ORDER_NUMBER IN (SELECT SALES_ORDER_NUMBER
                                    from PRODUCTS_BOUGHT
                                    where PRODUCT_NAME = :P36_PRODUCT_LISTING
                                   ) 
          ); 

我想生成如下输出:

CellData = "AAAAA" & Space & "BBBBB"

但是使用上面的代码,我只能生成:

"AAAAA" "BBBBB"

2 个答案:

答案 0 :(得分:2)

" "是一个空间,所以

?"AAAAA" & " " & "BBBBB"
AAAAA BBBBB

或者如果你想要引号

?"""AAAAA""" & " " & """BBBBB""
"AAAAA" "BBBBB"

当然是:

? """AAAAA"" ""BBBBB""
"AAAAA" "BBBBB"

Space如果您拥有的函数名称无效,您可以:

"AAAAA" & Space$(1) & "BBBBB"

单个空间。

答案 1 :(得分:2)

其中任何一个都可行:

Sub PrintSpace()
    Debug.Print "a" & Chr(32) & "a"
    Debug.Print "a" & " " & "a"
End Sub