ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Xls to Csv -- remove formatting (https://www.excelbanter.com/excel-programming/370251-re-xls-csv-remove-formatting.html)

NickHK

Xls to Csv -- remove formatting
 
Not sure why .SaveAs csv does not achieve your aim.
What are you trying to achieve ?

NickHK

"swtransaction"
wrote in message
news:swtransaction.2ci1rh_1155507619.4927@excelfor um-nospam.com...

I'm using this to convert XLS to CSv files in batch. The XLS files are
formatted and it would help a lot if they were not.

Can I automate removing the format? Thanks !!!!


Private Sub cmdXlsCsv_Click()

On Error GoTo MyError

Screen.MousePointer = vbHourglass

Dim xls As Excel.Application
Dim oWB As Excel.Workbook
Dim tmp As String
Set xls = New Excel.Application
tmp = Dir("C:\cmo\*.xls")
Do While tmp ""
Set oWB = xls.Workbooks.Open("C:\cmo\" & tmp)
'clear formatting here
oWB.SaveAs FileName:=Replace _
("C:\cmo\" & tmp, ".xls", ".csv", , , vbTextCompare), _
FileFormat:=xlCSVMSDOS, CreateBackup:=False
oWB.Close SaveChanges:=False
tmp = Dir
Set oWB = Nothing
Loop
xls.Quit
Set xls = Nothing

Screen.MousePointer = vbDefault

MyError:

If Err.Number = 1004 Then
MsgBox "Csv File Exists", vbOKOnly + vbExclamation
xls.Quit
Set xls = Nothing
Screen.MousePointer = vbDefault
End If
tabManage.SetFocus
End Sub


--
swtransaction
------------------------------------------------------------------------
swtransaction's Profile:

http://www.excelforum.com/member.php...o&userid=37459
View this thread: http://www.excelforum.com/showthread...hreadid=571210




swtransaction[_2_]

Xls to Csv -- remove formatting
 

Columns("A:Z").Select
Selection.NumberFormat = "@"

The code above does it (my spreadsheets never go past row Z)

Here was the problem, there were a couple columns formatted a
currency, so I was getting in the saved csv file:

xxxxx,"$3,001.45",xxxxxx

With that code above, it is now:

xxxxx,"3001.45",xxxxxx

No dollar signs or commas

It is working now!!

--
swtransactio
-----------------------------------------------------------------------
swtransaction's Profile: http://www.excelforum.com/member.php...fo&userid=3745
View this thread: http://www.excelforum.com/showthread.php?threadid=57121



All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com