Excel changes decimal separators when saved as *txt (using VBA)

Kra

Board Regular
Joined
Jul 4, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am using a macro to save sheet as *txt file. It works fine, but it changes decimal separators - from comma to dots. How to make sure it will keep commas?
I already checked my advanced settings:

1665419047903.png


Here is the input:
1665419079499.png



And here is how it looks after *txt file is saved
1665419092882.png




Here is a code I am using:

VBA Code:
Sub SaveTheFileText()
Dim ans As Long
Dim sSaveAsFilePath As String

    On Error GoTo ErrHandler:
    
    sSaveAsFilePath = "C:\AAA\ZVOL 9F LSMW.txt"

    If Dir(sSaveAsFilePath) <> "" Then
        ans = MsgBox("File " & sSaveAsFilePath & " exists.  Overwrite?", vbYesNo + vbExclamation)
        If ans <> vbYes Then
            Exit Sub
        Else
            Kill sSaveAsFilePath
        End If
    End If
    Worksheets("Pricelist").Copy '//Copy sheet to new workbook
    ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows '//Save as text (tab delimited) file
    'If ActiveWorkbook.Name <> ThisWorkbook.Name Then '//Double sure we don't close this workbook
       'ActiveWorkbook.Close False
    'End If

My_Exit:
Exit Sub

ErrHandler:
MsgBox Err.Description
Resume My_Exit

  
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try the following:

Change this line:

VBA Code:
ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows

For this:

Rich (BB code):
ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows, Local:=True
 
Upvote 0
Solution
Try the following:

Change this line:

VBA Code:
ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows

For this:

Rich (BB code):
ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows, Local:=True
Thank you so much! Fixed!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top