How to add append new Sheet in Excel?

How to add append new Sheet in Excel?

Postby hua » Mon Aug 13, 2012 8:08 pm

Guys, by default Excel creates 3 empty sheets, how do I add 2 more to the end of them so I end with Sheet1, Sheet2, Sheet3, Sheet4 and Sheet5 in sequence?

TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: How to add append new Sheet in Excel?

Postby Enrico Maria Giordano » Mon Aug 13, 2012 9:15 pm

A sample:

Code: Select all  Expand view
FUNCTION MAIN()

    LOCAL oExcel := CREATEOBJECT( "Excel.Application" )

    LOCAL oSheet

    oExcel:Workbooks:Add()

    oSheet = oExcel:Sheets:Add( oExcel:Sheets[ oExcel:Sheets:Count ] )

    oExcel:Sheets[ oExcel:Sheets:Count ]:Move( oSheet )

    oSheet:Name = "Added"

    oExcel:Visible = .T.

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to add append new Sheet in Excel?

Postby hua » Tue Aug 14, 2012 2:11 am

Thanks for the prompt response Enrico. Your solution has helped me.

Out of curiosity, can't we pass a parameter to :add() to indicate where the new sheet should be added?
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Re: How to add append new Sheet in Excel?

Postby hua » Tue Aug 14, 2012 7:30 am

Based on the link you've given (thanks!) and some tutorial here I try coding this way,
Code: Select all  Expand view
   oExcel:Sheets:Add(, oExcel:Sheets[ oExcel:Sheets:Count() ], 2 )


Seems to generate runtime error on my PC though. Couldn't get it to work
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: How to add append new Sheet in Excel?

Postby hua » Tue Aug 14, 2012 8:31 am

Found an old post of yours Enrico - https://groups.google.com/forum/?fromgr ... %5B1-25%5D

Is OleDefaultArg() available in both Harbour and xHarbour?
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: How to add append new Sheet in Excel?

Postby Enrico Maria Giordano » Tue Aug 14, 2012 8:52 am

xHarbour, for sure. Harbour, don't know, sorry.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to add append new Sheet in Excel?

Postby hua » Tue Aug 14, 2012 9:11 am

No problem. Thanks for your help and time
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 98 guests