Link to home
Start Free TrialLog in
Avatar of jamiepryer
jamiepryerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel 2003 vba - readline from xls

hi,
ive got some code for reading in files via a macro written in excel 2003.
The code works really well on .txt. or .csv files

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFile = objFso.OpenTextFile("c:\balh.txt)
strLine = objFile.ReadLine
arrStrLine = split(strline,vbtab)

however, when i try and read in an .xks file, it goes wrong and the line comes out with smething like this:
strLine: ""ÐÏࡱá>þÿ      ,°þÿÿÿbãdåfçhéjëlínïpñrót      õ      v""

is this because you cant use this method to read in an xls file?
is there another way to read xls files?
ASKER CERTIFIED SOLUTION
Avatar of borgunit
borgunit
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of INHOUSERES
INHOUSERES

borgunit, your suggestion uses early and late binding.

just change the dims to "as Object" rather than "excel.xxxx"
Avatar of Patrick Matthews
INHOUSERES,

Given that the Asker has stated that his/her code was written to be executed in Excel 2003, then I see nothing wrong at all with borgunit's variable declarations.

Patrick
jamie

Could the clue be in 'OpenTextFile'?

An Excel file is not a text file, though like any file you could treat it like one - but you'll just end up
with the gobblyedgook you are seeing.

What is it you are trying to do?

The easiest way to work with an Excel file is to open it as one using something like Workbooks.Open "C:\TheExcelFile.xls".
Avatar of jamiepryer

ASKER

Could the clue be in 'OpenTextFile'? - good point! cheers

will have a look at the replies tomorrow, thanks
matthewspatrick - I agree... I actually put it the wrong way round.

He's used early binding in the dims, and also doesn't really need to prefix it with "excel."
Then he uses late binding when setting the objects.

It would work, but there are neater ways to do it, which may be easier to read through for newer users of VBA and macro's etc.