How to fix TextFilePlatform in VBA code (error)

feni1388

Board Regular
Joined
Feb 19, 2018
Messages
158
Office Version
  1. 2021
Platform
  1. Windows
Hello everyone...

I have a VBA code to convert CSV to excel, but some computers can't display it correctly. The text was garbled.
I tried adding TextFilePlatform, but I got an error even before the macro starts.
TextFilePlatform:=932 was incorrect but I don't know how to fix it.
Can anyone help?

Thank you in advance



VBA Code:
' Open the CSV file
     Workbooks.OpenText Filename:=MyPath & LatestFile, DataType:=xlDelimited, Comma:=True, TextFilePlatform:=932
   
    ' Set the worksheet
    Set ws = ActiveSheet
   
'     Define the columns to be converted to date format (e.g., columns 2 and 4)
   dateColumns = Array(2, 3)
'
'     Loop through each column and convert to date format
    For i = LBound(dateColumns) To UBound(dateColumns)
       ws.Columns(dateColumns(i)).NumberFormat = "yyyy/mm/dd"
   Next i
   
   
    ' Define the columns to be changed to text format (e.g., columns 1 and 3)
    colToText = Array(1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40)

    ' Loop through the specified columns and change their format to text
    For j = LBound(colToText) To UBound(colToText)
        ws.Columns(colToText(j)).NumberFormat = "@"
    Next j
 
Ahhh
That line should look like
Rich (BB code):
     Workbooks.OpenText Filename:=MyPath & LatestFile, DataType:=xlDelimited, Comma:=True, Origin:= 65001
 
Upvote 0
Solution
Ahhh
That line should look like
Rich (BB code):
     Workbooks.OpenText Filename:=MyPath & LatestFile, DataType:=xlDelimited, Comma:=True, Origin:= 65001
It worked!!!!! Thank you so much...
 
Upvote 0
You are welcome and thanks for the feedback.
 
Upvote 0

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