I'm using this code from here to Transposed convert excel to csv file. It's working perfect (Thanks to Nat).
Now I'm facing an issue : as I want to read from this file to fill out Autocad table, I need to csv number format to be as "Text" format(now it's "General" format which is normally happening when it opens with excel). When I import my csv data, it omits leading zero cells and changing 1:100 to 0.01.
When I open csv file with excel and change those cells format to "Text", then save and close file, it's working fine. How can I automate this process (or save with Text format in the first place) as I don't want each user do this manually.
Thanks
Private Sub Exporttocsv()
Dim ColNum As Integer
Dim Line As String
Dim LineValues() As Variant
Dim OutputFileNum As Integer
Dim PathName As String
Dim RowNum As Integer
Dim SheetValues() As Variant
PathName = Application.ActiveWorkbook.Path
OutputFileNum = FreeFile
Open PathName & "\Test.csv" For Output Lock Write As #OutputFileNum
SheetValues = Sheets("Current Revision").Range("B2:CV98").value
Dim RowMax
RowMax = UBound(SheetValues)
Dim ColMax
ColMax = 99
ReDim LineValues(1 To RowMax)
For ColNum = 1 To ColMax
For RowNum = 1 To RowMax
LineValues(RowNum) = SheetValues(RowNum, ColNum)
Next
Line = Join(LineValues, ",")
Print #OutputFileNum, Line
Next
Close OutputFileNum
End Sub
SheetValues = Sheets("Current Revision").Range("B2:CV98").value
toSheetValues = Sheets("Current Revision").Range("B2:CV98").Text
will achieve what you want.csv
file looks like, you need to open it in something likeNotepad
. If you justopen
the file in Excel, there may be some unwanted conversions.