View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
No_Good_At_All No_Good_At_All is offline
external usenet poster
 
Posts: 2
Default Reading Sheet Names/Index from closed file using Biff8.

Search on the internet came up with a VB 6.0 programm to write a workbook
without Excel.
This code came from the source project witch you will find he

http://www.freevbcode.com/Source/006/vb%20Excel.zip

This link comes from:
http://www.freevbcode.com/ShowCode.Asp?ID=6856

Here's a bit of code from this source...........

' Procedure : Function Serialize
'---------------------------------------------------------------------------
------------
Public Function Serialize() As Byte()
Dim b() As Byte
Dim bname() As Byte

recLen = (Len(field_4_sheet_name)) + 12
ReDim b(recLen - 1)

CopyMemory b(0), ByVal VarPtr(ID), 2 ''' record
ID
b(2) = UBound(b) - 3 ''' Record
Length

CopyMemory b(4), ByVal VarPtr(field_1_stream_Position), 4 ''' Stream
Position
CopyMemory b(8), ByVal VarPtr(field_2_visibility), 1 '''
Visibility

b(9) = field_3_sheet_type ''' sheet
type
b(10) = Len(field_4_sheet_name) ''' Name
length

b(11) = 0 ''' Unicode
flag (compressed String)
bname = StrConv(field_4_sheet_name, vbFromUnicode)
CopyMemory b(12), bname(0), UBound(bname) + 1 ''' sheet
name

Serialize = b
End Function

--
Maybe this will help....................

Greetz,

No_Good_At_All





"keepITcool" schreef in bericht
...
Thanks for the suggestion, but alas....

As far as i can figure..Offset 4 thru 8 are a long representing the
position of the worksheet stream in the file. The fact that offset 6
is 0 means the stream is further down the file..


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"No_Good_At_All" wrote :

I'm no good at vba but tried to take a closer look.......

Looking for the wrong value?

I changed the code a bit to write the values to the sheet and i also
added a dialog sheet, a xl4 macro sheet etc.
When i look at the written values i see that aByt(6) is a zero for
every sheet, except for the worksheets.
If it's a worksheet, the value is greater than zero.

Hope this helps




"keepITcool" schreef in bericht
...

Hi guys

ADO (Jet) needs Sheet Names and cannot use indexes. (Since tables in
databases would have no 'ordinal' position)

To give myself a bit (or byte) of flexibility I'm trying to come up
with a little structure reader for closed files. I've got a nice
simple routine... Problem is it will recognize a DialogSheet as a
Worksheet

To be precise it returns a 0 (worksheet) in byte 9 of the BoundsSheet
record...

So I assume I've got to jump to the stream itself.. but I haven;t
figured out how (yet) I presume I must use the Long at offset 4 in
the record as my target address?

Anyone any ideas? (or working code?)
My code below.. Now a bad start as is :)


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


Function ReadSheets(sFullName As String, _
Optional bWorksheetsOnly As Boolean = True) As Collection
'Returns a collection of the sheets in a workbook.

Dim lHnd&, lLen&, lPos&, aByt() As Byte, cRes As Collection
Dim iPos&, iTyp%, sTxt$

Const IDboundsheet = &H85
Const BuffSize = &H400

If Dir(sFullName) = vbNullString Then Exit Function

Set cRes = New Collection
ReDim aByt(0 To BuffSize)
lLen = FileLen(sFullName)
lHnd = FreeFile

Open sFullName For Binary Access Read As #lHnd Len = BuffSize

Do
lPos = lPos + BuffSize - 1
Get #lHnd, lPos, aByt
iPos = InStrB(aByt, ChrB(IDboundsheet))
Loop While iPos = 0 And lPos < lLen

Do While iPos 0
lPos = lPos + iPos - 1
Get #lHnd, lPos, aByt
sTxt = Mid(StrConv(aByt, vbUnicode), 13, aByt(10))
iTyp = aByt(9)

cRes.Add Array(sTxt, iTyp), sTxt
If aByt(aByt(2) + 4) < IDboundsheet Then
iPos = 0
Else
iPos = InStrB(4, aByt, ChrB(&H85))
End If
Loop

Close #lHnd
Set ReadSheets = cRes

End Function