Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create table and field listing of database tables in excel

COM and Automation

create table and field listing of database tables in excel

by  danceman  Posted    (Edited  )
This creates an excel file with a work sheet labled with the table name. each sheet list the field name with the data type and format.

close databases
open database data\pcm
lnf = 0
lnt = 0
sloc = '

obj = createobject('excel.application')
** set excel to only have one worksheet
obj.Application.SheetsInNewWorkbook = 1
** delete the work book that has three worksheets
obj.Application.Workbooks.close
now add a new book with only one worksheet
obj.Application.Workbooks.Add

** uncoment this line to watch it work.
*obj.Application.visible = .t.

** fox fuction to get table list from open database
lnt = ADBOBJECTS(gaTables, "TABLE")

** loop through list of tables
for i = 1 to lnt
use gaTables(i)
lnf = afields(gaFields,gaTables(i))

** avoid adding a worksheet on the first time around
if i != 1
obj.Application.Workbooks(1).worksheets.Add
endif
obj.Application.Workbooks(1).Worksheets(1).activate
obj.Application.Workbooks(1).Worksheets(1).name = gaTables(i)
use
obj.Application.Workbooks(1).Worksheets(1).cells(1,1).Value = 'Name'
obj.Application.Workbooks(1).Worksheets(1).cells(1,2).Value = 'Char Type'
obj.Application.Workbooks(1).Worksheets(1).cells(1,3).Value = 'Width'
obj.Application.Workbooks(1).Worksheets(1).cells(1,4).Value = 'Dec. Pos'
for j = 1 to lnf
obj.Application.Workbooks(1).Worksheets(1).cells(j+1,1).Value = gaFields(j,1)
obj.Application.Workbooks(1).Worksheets(1).cells(j+1,2).Value = gaFields(j,2)
obj.Application.Workbooks(1).Worksheets(1).cells(j+1,3).Value = gaFields(j,3)
obj.Application.Workbooks(1).Worksheets(1).cells(j+1,4).Value = gaFields(j,4)
next
next

close databases

obj.Application.Workbooks(1).SaveAs('c:\vpcmatrix\pcm.xls')
obj.Application.quit
release obj
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top