-1

I am well-versed in Excel vba that I use for work, but I chose to use LibreOffice for this personal project because I don't have a personal MS Office license. Below is the code I currently have written.

Sub Setup
    Dim oSheets
    Dim oBoardSheet
    Dim oTurnSheet
    Dim sReturn As String
    Dim iRoll As Integer
    Dim sIBinfo As String
    Dim sIBMsg As String
    Dim sIBTitle As String
    Dim sNewSheet As String
    
    oSheets = ThisComponent.Sheets
    sNewSheet = Format(Now,"mm-dd-yy")
    oSheets.insertNewByName(sNewSheet,2)
    
    oBoardSheet = oSheets.getByName("3-4PlayerBoard")
    oTurnSheet = oSheets.getByName(sNewSheet)
  • And what problems did you encounter? Indeed, `.insertNewByName()` will create a new sheet with the specified name at the specified location. Possible error - a sheet with the same name already exists. It makes sense to make sure it doesn't already exist with [**.hasByName()**](http://www.openoffice.org/api/docs/common/ref/com/sun/star/container/XNameAccess.html#hasByName). A new sheet name can be set using [**.setName()**](http://www.openoffice.org/api/docs/common/ref/com/sun/star/container/XNamed.html#setName) (again, you should make sure that there is no such name yet) – JohnSUN Mar 12 '22 at 06:54

1 Answers1

0

LO has 2 ways of creating macro: recording macro that records some user actions via dispatcher (not recommended) and API real code that should be typed or created using MRI extension. Short overview of Calc Basic code is at https://wiki.documentfoundation.org/Macros/Basic/Calc and https://documentation.libreoffice.org/en/english-documentation/macro/ and full Pitonyak guide at https://www.pitonyak.org/oo.php.

Seems like parenthesis missing.

oSheets = ThisComponent.getSheets()  
oSheets.insertNewByName("sNewSheet", 2)
Timso
  • 24
  • 4