因此,您已经获得了数据并将其写入文本文件。假设您的数据在一个数组中,我将遍历数组并在将数据转换为字符串后转换数据,就像这样。
Sub ChangeDecimalSeperator()
Dim vData As Variant, ii As Integer, jj As Integer
vData = ActiveSheet.Range("A1:B2")
For ii = LBound(vData, 1) To UBound(vData, 1)
For jj = LBound(vData) To UBound(vData, 2)
'Only convert if it's a number
If VBA.IsNumeric(vData(ii, jj)) Then
'You can also specify the format using VBA.Format$() here, ie force the decimal places
vData(ii, jj) = ReplaceCharacter(VBA.CStr(vData(ii, jj)), ".", ",")
End If
Next jj
Next ii
'Now output vData to your textfile
End Sub
Function ReplaceCharacter(sForString As String, sReplacingCharacter As String, sWithCharacter As String) As String
Dim sStringPrevious As String
'While there is a character that we still need replacing left, keep going. If we can't find one, we're done
Do
sStringPrevious = sForString
sForString = VBA.Replace(sForString, sReplacingCharacter, sWithCharacter)
Loop Until sStringPrevious = sForString
ReplaceCharacter = sForString
End Function