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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

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