将选定的单元格导出为不带“引号”的.txt文件

我正在做一个获取大量信息的Excel工作表。 一些列有我需要在脚本中使用的信息,我使用下面的代码,我发现保存我select一个.txt文件后,我点击一个button。

Private Sub CommandButton21_Click() Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer myFile = Application.DefaultFilePath & "\NumeroChamados.txt" Set rng = Selection Open myFile For Output As #1 For i = 1 To rng.Rows.Count For j = 1 To rng.Columns.Count cellValue = rng.Cells(i, j).Value If j = rng.Columns.Count Then Write #1, cellValue Else Write #1, cellValue, End If Next j Next i Close #1 End Sub 

事情是我保存的一切结束与引用如下例:

 "4146546546523133" "4285725763131" "461" "4230236646435356694197285187451644148" "4230375763756379653464564" 

我select的单元格通常包含来自另一个单元格的string,在这个单元格中我使用macros来获取它。

为了避免在Excel中解释为一个string(即使是文本看起来像一个数字)的任何东西的包装引号,使用Print而不是Write

 Private Sub CommandButton1_Click() Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer myFile = Application.DefaultFilePath & "\NumeroChamados.txt" Set rng = Selection Open myFile For Output As #1 For i = 1 To rng.Rows.Count For j = 1 To rng.Columns.Count cellValue = rng.Cells(i, j).Value If j = rng.Columns.Count Then Print #1, cellValue Else Print #1, cellValue, End If Next j Next i Close #1 End Sub 

在这里输入图像说明