XL.Book.AddSheet
----------------

Adds a new sheet to this book, returns the sheet index.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [XL](component_XL.md) | [3.5](newinversion35.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "XL.Book.AddSheet"; BookRef; Name { ; InitSheet } ) 

**MBS**( **"XL.Book.AddSheet";** /\* Adds a new sheet to this book, returns the sheet index. \*/  
**$BookRef**; /\* The reference number for the workbook.e.g. $ref \*/   
**$Name**; /\* The name for the new sheet.e.g. "Taxsheet" \*/   
**$InitSheet**) /\* Optional; The index of an existing sheet to use as template.  
Must be from the same book to copy sheet.e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| BookRef | The reference number for the workbook. | $ref |  |
| Name | The name for the new sheet. | "Taxsheet" |  |
| InitSheet | The index of an existing sheet to use as template.   Must be from the same book to copy sheet. | 0 | Optional |

### Result

Returns new sheet index or error message.

### Description

Adds a new sheet to this book, returns the sheet index.   
Use initSheet parameter if you wish to copy an existing sheet.   
Note initSheet must be only from this book.   
### Examples

Writes sheet with red font:

 #create new xls file   
Set Variable \[$book ; Value:MBS ( "[XL.NewBook](XLNewBook.md)"; 0 )\]  
\#create fonts   
Set Variable \[$redColor ; Value:MBS ( "[XL.Color.Pack](XLColorPack.md)"; $book ; 255; 0; 0)\]  
Set Variable \[$redFont ; Value:MBS ( "[XL.Book.AddFont](XLBookAddFont.md)"; $book )\]  
Set Variable \[$r ; Value:MBS ( "[XL.Font.SetColor](XLFontSetColor.md)"; $book ; $redFont ; $redColor )\]  
\#   
\#create formats   
Set Variable \[$redFormat ; Value:MBS ( "[XL.Book.AddFormat](XLBookAddFormat.md)"; $book )\]  
Set Variable \[$r ; Value:MBS ( "[XL.Format.SetFont](XLFormatSetFont.md)"; $book ; $redFormat ; $redFont )\]  
\#   
\#create sheet   
Set Variable \[$sheet ; Value:MBS ( "XL.Book.AddSheet"; $book ; "Sales Receipt")\]  
\#   
\#add number in red   
Set Variable \[$r ; Value:MBS ( "[XL.Sheet.CellWriteNumber](XLSheetCellWriteNumber.md)"; $book ; $sheet ; 5; 3; 123; $redFormat )\]  
\#   
Set Field \[Writing data::Output ; MBS ("[XL.Book.Save](XLBookSave.md)"; $book ; "test.xls")\]  
Set Variable \[$r ; Value:MBS ("[XL.Book.Release](XLBookRelease.md)"; $book )\]  
### See also

- [XL.Book.MoveSheet](XLBookMoveSheet.md)
- [XL.Color.Pack](XLColorPack.md)
- [XL.Date.Pack](XLDatePack.md)
- [XL.Format.SetFont](XLFormatSetFont.md)
- [XL.Format.SetWrap](XLFormatSetWrap.md)
- [XL.NewBook](XLNewBook.md)
- [XL.Sheet.AddDataValidation](XLSheetAddDataValidation.md)
- [XL.Sheet.AddTable](XLSheetAddTable.md)
- [XL.Sheet.CellWriteNumber](XLSheetCellWriteNumber.md)
- [XL.Sheet.SetCol](XLSheetSetCol.md)

### Release notes

- **Version 13.0**
    - Fixed a problem with [XL.Book.AddSheet](https://www.mbsplugins.eu/XLBookAddSheet.shtml) function not passing correct name each time.

### Example Databases

- [XL/AutoFilter](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/AutoFilter.shtml#1ScriptAnchor_)
- [XL/Conditional Formatting](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/Conditional%20Formatting.shtml#1ScriptAnchor_)
- [XL/Export records](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/Export%20records.shtml#2ScriptAnchor_)
- [XL/Writing data](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/Writing%20data.shtml#5ScriptAnchor_)
- [XL/XL Import and Export](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XL/XL%20Import%20and%20Export.shtml#4ScriptAnchor_)

### Blog Entries

- [MBS Plugin Advent calendar: 13 - XL](https://www.mbsplugins.de/archive/2023-12-13/MBS_Plugin_Advent_calendar_13_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.6pr1](https://www.mbsplugins.de/archive/2022-12-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Use formatted text in Excel files with FileMaker and LibXL](https://www.mbsplugins.de/archive/2020-04-23/Use_formatted_text_in_Excel_fi/monkeybreadsoftware_blog_filemaker)
- [How to use XL functions with MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2015-02-09/How_to_use_XL_functions_with_M/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 5/2022, Seite 22](https://filemaker-magazin.de/neuigkeit/4196-Appetithappen-FMM_202205)

This function checks for a license.

Created 18th August 2014 , last changed 18th May 2023

  
[XL.Book.AddPictureFile](XLBookAddPictureFile.md) - [XL.Book.BiffVersion](XLBookBiffVersion.md)

[HTML Version](XLBookAddSheet.shtml)