Jump to content
Sign in to follow this  
BugFix

Enhanced parameter for _ExcelBookNew( )

Recommended Posts

BugFix

Hi,

by creation of an new ExcelBook, we get an default value of sheets (if not user defined: 3).

To make it more flexible, i've added an parameter "$iSheetsStartup" in function _ExcelBookNew(). The default value is '1'.

What do you mean, make it sense to enhance the function in Excel-UDF with this parameter?

Func _ExcelBookNew($fVisible = 1, $iSheetsStartup = 1)
    Local $oExcel = ObjCreate("Excel.Application")
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If Not IsNumber($fVisible) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    If $iSheetsStartup < 1 Then $iSheetsStartup = 1
    With $oExcel
        .SheetsInNewWorkbook = $iSheetsStartup
        .Visible = $fVisible
        .WorkBooks.Add
        .ActiveWorkbook.Sheets(1).Select ()
    EndWith
    Return $oExcel
EndFunc

Best Regards BugFix  

Share this post


Link to post
Share on other sites
PsaltyDS

Hi,

by creation of an new ExcelBook, we get an default value of sheets (if not user defined: 3).

To make it more flexible, i've added an parameter "$iSheetsStartup" in function _ExcelBookNew(). The default value is '1'.

What do you mean, make it sense to enhance the function in Excel-UDF with this parameter?

Func _ExcelBookNew($fVisible = 1, $iSheetsStartup = 1)
    Local $oExcel = ObjCreate("Excel.Application")
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If Not IsNumber($fVisible) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    If $iSheetsStartup < 1 Then $iSheetsStartup = 1
    With $oExcel
        .SheetsInNewWorkbook = $iSheetsStartup
        .Visible = $fVisible
        .WorkBooks.Add
        .ActiveWorkbook.Sheets(1).Select ()
    EndWith
    Return $oExcel
EndFunc
No, I think the default for Excel should be left alone. I like the idea of having the parameter, but it's default should be to leave .SheetsInNewWorkbook alone.

Func _ExcelBookNew($fVisible = 1, $iSheetsStartup = -1)
    Local $oExcel = ObjCreate("Excel.Application")
    If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
    If Not IsNumber($fVisible) Then Return SetError(2, 0, 0)
    If $fVisible > 1 Then $fVisible = 1
    If $fVisible < 0 Then $fVisible = 0
    With $oExcel
        If $iSheetsStartup > 0 Then .SheetsInNewWorkbook = $iSheetsStartup
        .Visible = $fVisible
        .WorkBooks.Add
        .ActiveWorkbook.Sheets(1).Select ()
    EndWith
    Return $oExcel
EndFunc

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
BugFix

.. but it's default should be to leave .SheetsInNewWorkbook alone.

Yes, you're right. This is a better way. :)


Best Regards BugFix  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×