ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA (https://www.excelbanter.com/excel-programming/416604-vba.html)

Alberto Brivio

VBA
 
Dear All,

as you can see, this is an instruction to save a .CSV file from an excel
file, but this conversion keep 2 decimal places only, so my question is how
can I get 4 decimal places?

instruction is

If iUno < 0 And iDue < 0 Then
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open sNomeFile, 0, True
sNomeFile = Replace(UCase(sNomeFile), "PRICES", "PricesNew")
sNomeFile = Replace(UCase(sNomeFile), ".XLS", ".csv")
objExcel.ActiveWorkbook.SaveAs sNomeFile, xlTextMSDOS, False
(***)
objExcel.Close
objExcel = Nothing
End If


Regards

Alberto Brivio




joel

VBA
 
Convert each number to text before making the sheet CSV

Cell = Format(Cell.Value, "@")


If iUno < 0 And iDue < 0 Then
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open sNomeFile, 0, True
sNomeFile = Replace(UCase(sNomeFile), "PRICES", "PricesNew")
sNomeFile = Replace(UCase(sNomeFile), ".XLS", ".csv")

With objExcel.ActiveWorkbook.ActiveSheet
Set LastCell = .Cells _
.SpecialCells(xlCellTypeLastCell)
Set ShtRange = .Range("A1", LastCell)
End With
For Each Cell In ShtRange
If IsNumeric(Cell) Then
Cell = Format(Cell.Value, "@")
End If
Next Cell
objExcel.ActiveWorkbook.SaveAs sNomeFile, xlTextMSDOS, False

objExcel.Close
objExcel = Nothing
End If


"Alberto Brivio" wrote:

Dear All,

as you can see, this is an instruction to save a .CSV file from an excel
file, but this conversion keep 2 decimal places only, so my question is how
can I get 4 decimal places?

instruction is

If iUno < 0 And iDue < 0 Then
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open sNomeFile, 0, True
sNomeFile = Replace(UCase(sNomeFile), "PRICES", "PricesNew")
sNomeFile = Replace(UCase(sNomeFile), ".XLS", ".csv")
objExcel.ActiveWorkbook.SaveAs sNomeFile, xlTextMSDOS, False
(***)
objExcel.Close
objExcel = Nothing
End If


Regards

Alberto Brivio





Dave Peterson

VBA
 
I ran a skinnied down version of your macro in xl2003 and it kept lots more than
2 digits.

Do you have a number format applied to the data (in excel)?

Are the last 2 decimal places 0?

Are you checking the output by opening the CSV file in Notepad?

If you're opening in excel, try widening the columns after you open the .csv
file.

Alberto Brivio wrote:

Dear All,

as you can see, this is an instruction to save a .CSV file from an excel
file, but this conversion keep 2 decimal places only, so my question is how
can I get 4 decimal places?

instruction is

If iUno < 0 And iDue < 0 Then
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open sNomeFile, 0, True
sNomeFile = Replace(UCase(sNomeFile), "PRICES", "PricesNew")
sNomeFile = Replace(UCase(sNomeFile), ".XLS", ".csv")
objExcel.ActiveWorkbook.SaveAs sNomeFile, xlTextMSDOS, False
(***)
objExcel.Close
objExcel = Nothing
End If

Regards

Alberto Brivio


--

Dave Peterson


All times are GMT +1. The time now is 03:00 PM.

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