FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to add append new Sheet in Excel?
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
How to add append new Sheet in Excel?
Posted: Mon Aug 13, 2012 08: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to add append new Sheet in Excel?
Posted: Mon Aug 13, 2012 09:15 PM
A sample:

Code (fw): Select all Collapse
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
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: How to add append new Sheet in Excel?
Posted: Tue Aug 14, 2012 02: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to add append new Sheet in Excel?
Posted: Tue Aug 14, 2012 06:50 AM
No that I'm aware of. From the MSDN:

http://msdn.microsoft.com/en-us/library/office/ff839847.aspx

EMG
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: How to add append new Sheet in Excel?
Posted: Tue Aug 14, 2012 07:30 AM
Based on the link you've given (thanks!) and some tutorial here I try coding this way,
Code (fw): Select all Collapse
    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
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: How to add append new Sheet in Excel?
Posted: Tue Aug 14, 2012 08: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to add append new Sheet in Excel?
Posted: Tue Aug 14, 2012 08:52 AM

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

EMG

Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: How to add append new Sheet in Excel?
Posted: Tue Aug 14, 2012 09:11 AM

No problem. Thanks for your help and time

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion