从Excel转换为文本文件时如何删除双引号?

时间:2019-08-27 20:07:59

标签: excel vba

由于某种原因,每次我使用此代码时,单元格的输出从开始到结束都会出现双引号。无论如何,如何删除这些引号?

我尝试使用基本的VBA,在该VBA中,它从特定列中复制数据并将其转换为txt文件。

Dim s As String, FileName As String, FileNum As Integer

  ' Define full pathname of TXT file
  FileName = ThisWorkbook.Path & "\2019.con"

  ' Copy range to the clipboard
  Range("A2", Cells(Rows.Count, "A").End(xlUp)).Copy

  ' Copy column content to the 's' variable via clipboard
  With New DataObject
     .GetFromClipboard
     s = .GetText
  End With
  Application.CutCopyMode = False

  ' Write s to TXT file
  FileNum = FreeFile
  If Len(Dir(FileName)) > 0 Then Kill FileName
  Open FileName For Binary Access Write As FileNum
  Put FileNum, , s
  Close FileNum

Actual Result: "CONT=10" "." "." "."

Desired Result: CONT=10 . . .

1 个答案:

答案 0 :(得分:3)

如果您不想使用引号,则应使用Print而不是Write