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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send a cursor to Excel 2

Status
Not open for further replies.

AllCaz

Programmer
Dec 5, 2000
12
0
0
US
I use this code when I want to copy a cursor or table over to Excel so I can easily sort it or otherwise mess with it.

Local lcFile
lcFile = 'c:\temp\export.xls'

COPY TO &lcFile TYPE XL5

oExcel = CREATEOBJECT('Excel.Application')
oExcel.Visible = .T.

if !file(lcFile)
=MESSAGEBOX(lcfile + ' not found!')
return
endif

oExcel.Application.Workbooks.Open(lcFile)

WAIT WINDOW "Click the VFP window to finish."

oExcel.Workbooks.Close
oExcel.Quit
Release oExcel
 
Excuse me, (blush), emm..
How do you know these commands ?

oExcel.Application.Workbooks.Open(lcFile)
oExcel.Workbooks.Close
oExcel.Quit

I can't find in FoxPro Help.
 
The name of the Excel programming help file is VBAXL9.CHM. Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
I have a question that relates directly to this.
seems the excel 97 has a limit on the number of rows that can be imported. I would like to sort first then open the excel export 1 worksheet. <-that works for me.
count to like 64000 then create a second worksheet in the same file. <-this part I dont know how to do.
and so on.
Im not going to go into the part about joining worksheets to create charts.
I have to use excel for my users benefit.
Thanks.
Go Canucks! (rabid Vancouver Canucks Fan)
 
oExcel = CREATEOBJECT('Excel.Application')
oExcel.Visible = .T.
oExcel.application.workbooks.add
oExcel.application.workbooks(1).activate
oExcel.application.workbooks(1).sheets(1).activate
*run 1rst 64000
oExcel.application.workbooks(1).sheets(2).activate
*run 2nd 64000 etc
oExcel.quit &&Excell will prompt you to save the file
RELEASE oExcel
-Pete
 
How about:

oExcel = CREATEOBJECT('Excel.Application')
oExcel.Visible = .T.
oExcel.workbooks.add()

*compute number of sheets
lnNumOfSheets=(RECCOUNT()/65536)
lnNumOfSheets=INT(lnNumOfSheets) + 1
lnNumOfSheets = lnNumOfSheets - oExcel.Sheets.Count
oExcel.sheets.add(,,lnNumOfSheets)
lnNumOfSheets=oExcel.Sheets.Count

*loop thru the sheets
FOR X = 1 TO lnNumOfSheets
oSheet=oExcel.Sheets(X)
WITH oSheet
.Activate()
.Name=&quot;Sheet&quot;+TRANS(X)
*do whatever else you would like
ENDWITH
ENDFOR

*save it and quit
oExcel.WorkBooks(1).SaveAs('C:\mysheet.xls')
oExcel.WorkBooks(1).Close(.F.)
oExcel.Quit Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top