Import text file problem

  • Thread starter Thread starter condotta
  • Start date Start date
C

condotta

Hello,

I have this code which imports from a text file but the data is placed
in the cells as a string until an {F2} and {enter} are preformed
forcing the cell format to take over. Is there a neat way to do this on
a large amount of cells and within my function?

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFS.OpenTextFile(sFileName, ForReading, False,
0)

With ImportRange

' Get to the starting position for the sequential import range
in the text file
If giEndLine <> 1 Then
For I = 1 To giEndLine - 1
objTextFile.SkipLine
Next
End If
Application.Calculation = xlCalculationManual
For Each vrow In .Cells.Rows
WholeLine = objTextFile.ReadLine
vrow.Value = Split(WholeLine, ";")
Next
Application.Calculation = xlCalculationAutomatic
' Set last line in range for global variable for next range.
giEndLine = objTextFile.Line

End With

objTextFile.Close
Set objTextFile = Nothing
Set objFS = Nothing

Regards,

Stefano
 
Sorry for the vague description. For those interested, I found the
answer in another post. To get all imported text/string values back to
their formats simply copy a blank cell to the imported values and
pastespecial with xlpastevalues and xlpastespecialoperationadd. That
does the trick.

Regards,

Stefano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top