我尝试了以下几种变体,但没有任何效果:
Private Sub CommandButton1_Click()
Dim FilePath As String
Dim CellData As String
StockCode = Range("H1").Value
JobNumber = Range("H2").Value
Comma = ","
TheDateTime = Month(Now) & Day(Now) & Year(Now) & Hour(Now) & Minute(Now) & Second(Now)
CellData = StockCode
CellData = CellData & """,""" & JobNumber & """,""" & TheDateTime
FilePath = Application.DefaultFilePath & "\TextFile.txt"
Open FilePath For Output As #1
Write #1, CellData
CellData = ""
Close #1
End Sub
如何获取"数据","数据","数据"格式?
答案 0 :(得分:1)
Write #
语句在字符串写入文件时在字符串和引号之间插入逗号。您不必在列表中放置明确的分隔符。见这里:Write # Statement
尝试使用Write #1, StockCode, JobNumber, TheDateTime
,而不是将所有这些内容连接到CellData
。