BugFix Posted October 27, 2009 Share Posted October 27, 2009 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 27, 2009 Share Posted October 27, 2009 (edited) 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 October 27, 2009 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 Link to comment Share on other sites More sharing options...
BugFix Posted October 27, 2009 Author Share Posted October 27, 2009 .. but it's default should be to leave .SheetsInNewWorkbook alone.Yes, you're right. This is a better way. Best Regards BugFix Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now