View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
mrice mrice is offline
external usenet poster
 
Posts: 1
Default Batch converting CSV files from comma-decimal to period-decimal


Try the following VBA

Const SourceFilePath = "C:\tempsource\"
Const TargetFilePath = "C:\temptarget\"


Sub Convert()
Close
Filename = Dir(SourceFilePath & "*.csv")
Do While SourceFilePath < ""
Open SourceFilePath & Filename For Input As #1
Open TargetFilePath & Filename For Output As #2
Do While Not EOF(1)
Line Input #1, FileLine
FileLine = Application.Substitute(FileLine, ".", "") 'changes .
to nothing
FileLine = Application.Substitute(FileLine, ",", ".") 'changes
, to .
FileLine = Application.Substitute(FileLine, ";", ",") 'changes
; to ;
Print #2, FileLine
Loop
Close #1
Close #2
Filename = Dir()
Loop
End Sub

You need to create the tempsource and temptarget directories. Copy the
files into the tempsource folder and the macro will populate the
temptarget folder with the modified files.

Good luck!


--
mrice

Research Scientist with many years of spreadsheet development experience
------------------------------------------------------------------------
mrice's Profile: http://www.excelforum.com/member.php...o&userid=10931
View this thread: http://www.excelforum.com/showthread...hreadid=558251