I have this code bellow that upload a csv
file in my MSHFlexgrid1.
The problem is that i would like to upload the file in in grid as a TEXT
The reason is that in my csv file, i may see text like 012345
but once in the grid, it convert the text to 12345
by removing the 0
How can i do that?
Thanks again for your help
Private Sub FetchNoRowCol(ws As Excel.Worksheet, ByRef NoOfRows As Long, _
ByRef NoOfColumns As Long)
' Error-handling is here in case there is not any
' data in the worksheet.
On Error Resume Next
NoOfRows = ws.Cells.Find(What:="*", SearchDirection:=xlPrevious, _
NoOfColumns = ws.Cells.Find(What:="*", SearchDirection:=xlPrevious, _
Private Sub Command1_Click()
Dim xlObject As Excel.Application
Dim xlWB As Excel.Workbook
Dim NoOfRows As Long
Dim NoOfColumns As Long
.CancelError = True
.Filter = "Microsoft Excel files (csv)"
.InitDir = "C:\Documents and Settings\all users\Desktop"
If Not .FileName = "" Then
Set xlObject = New Excel.Application
Set xlWB = xlObject.Workbooks.Open(.FileName)
xlObject.Cells.Copy ' Copy all cells in active worksheet.
FetchNoRowCol xlObject.ActiveWorkbook.ActiveSheet, NoOfRows, NoOfColumns
.Redraw = False 'Dont draw until the end, so we avoid that flash
.Rows = NoOfRows
.Cols = NoOfColumns
.Row = 0 'Paste from first cell
.Col = 0
.RowSel = .Rows - 1 'Select maximum allowed (your selection shouldnt be greater than this)
.ColSel = .Cols - 1
.Clip = Replace(Clipboard.GetText, vbNewLine, vbCr) 'Replace carriage return with the correct one
.Col = 1 'Just to remove that blue selection from Flexgrid
.Redraw = True 'Now draw
xlObject.DisplayAlerts = False 'To avoid "Save woorkbook" messagebox
Set xlWB = Nothing
Set xlObject = Nothing