jamiepryer
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.Fi leSystemOb ject")
Set objFile = objFso.OpenTextFile("c:\ba lh.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?
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.Fi
Set objFile = objFso.OpenTextFile("c:\ba
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: ""ÐÏࡱá
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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".
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".
ASKER
Could the clue be in 'OpenTextFile'? - good point! cheers
will have a look at the replies tomorrow, thanks
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.
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.
just change the dims to "as Object" rather than "excel.xxxx"