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

How do I properly Add a new sheet in Excel?

Status
Not open for further replies.

medic

Programmer
Jun 14, 2000
459
US
Hi guys!

Can anybody help me how to properly Add a new sheet in excel? My problem is when I simply issue the Add method without the necessary parameters (which I don't know how to invoke in VFP), the new sheet positions itself before the last sheet in the workbook. What I want is to place the new sheet after the last sheet (rightmost). Here's my sample code:

[tt]
oExcel=createobject('Excel.Application')
oExcel.Visible=.T.
xlfile="myfile.xls"
oExcel.Application.Workbooks.Open(xlfile)
.
.
oExcel.Application.Workbooks(1).Sheets.Add
[/tt]

I need to know how to set the After and Before options. I know how to do this in VB but not in VFP.
 
HI

** How to avoid limiting the records in excel
oExcel = CREATEOBJECT('Excel.Application')
oExcel.Visible = .T.
oExcel.workbooks.add()

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

:) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Thanks for the response ramani!

But I have a question. Why does VFP reports an error

Error 1426: OLE error code 0x800a03ec: Uknown OLE status code.

when I issue the command
[tt]
oExcel.sheets.add(,,10)
[/tt]
Any idea? :)

Medic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top