How to Use a .ODS file with Macro created in Calc on Windows in a MacBook

Hi

I want to know if a spreadsheet with a macro created in LibreOffice Calc can be used using a MacBook.

Will there be any problems opening the file once LibreOffice is installed in the new MacBook and will the mac operating system be able to handle the simple macro previously created on the Windows version of LO Calc?

Thank you

Terry

Depends on the Security-settings for LO on the Macbook

Depends on the actual macrocode … (why dont you post it?) … wich may be »Window-specific« or not!

1 Like

Hi Karolus

I am posting this macro to see if you or anyone thinks it will work with LibreOffice calc macos.

REM ***** BASIC *****

Sub CopyPricesToPriceHistoryRev1
REM created by 12Feb24

dim document   as object
dim dispatcher as object

REM get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

REM Define sheet names
oDocument = ThisComponent   'assigns the current document to the variable document
Controller = oDocument.getcurrentController
oSheets =oDocument.Sheets
priceSheet = oSheets.getByName("Prices")
histSheet  = oSheets.getByName("Price History")

REM make Prices sheet active 
Controller.setActiveSheet(priceSheet)

REM copy cells D4 to D38 on Prices sheet
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ToPoint"
args3(0).Value = "$D$4:$D$43"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())


REM Make Price History sheet active
Controller.setActiveSheet(histSheet)

REM Find the first empty column in row 4 in the Prices History sheet
eCells   = histSheet.Rows(3).QueryEmptyCells
finRg    = eCells(eCells.Count - 1)
If finRg.RangeAddress.EndColumn<>histSheet.RangeAddress.endColumn Then Exit Sub
target   = finRg.GetCellByPosition(0, 0)
oDocument.CurrentController.Select(target)

REM get address of cell to paste to
oActivecell = ThisComponent.CurrentSelection
oConv = oDocument.createInstance("com.sun.star.table.CellAddressConversion")
oConv.Address = oActiveCell.getCellAddress
activecellStr = oConv.PersistentRepresentation         REM output format "Prices.B6"
addrArray = split(activecellStr,".")
targetAddr = addrArray(ubound(addrArray))		REM assign last element in address array
REM print targetAddr

wait 1000    REM this is a 1000 millisecond (1 second) pause


REM Paste special to target cell
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "ToPoint"
args7(0).Value = targetAddr
dispatcher.executeDispatch(document, ".uno:PasteOnlyValue", "", 0, Array())

End Sub

sub test
oDocument = ThisComponent 'assigns the current document to the variable document
Controller = oDocument.getcurrentController
oSheets =oDocument.Sheets
priceSheet = oSheets.getByName(“Prices”)
histSheet = oSheets.getByName(“Price History”)

oActivecell = ThisComponent.CurrentSelection
oConv = oDocument.createInstance("com.sun.star.table.CellAddressConversion")
oConv.Address = oActiveCell.getCellAddress

activecellStr = oConv.PersistentRepresentation         REM output format "Prices.B6"
addrArray = split(activecellStr,".")
targetAddr = addrArray(ubound(addrArray))
print targetAddr

end sub

Thanks

Terry

apart from the messy code, I can’t find anything that shouldn’t work on the MacBook

1 Like

Hi Karolus

I appreciate your help. I am not an expert and the vba if that is what it is isn’t mine for that reason. To be clear as far as you can see this code should run?

Also, when one sets up libreoffice/Calc in macos MacBook is there anything substantially different to set up to ensure the spreadsheet .ods and the macro over and above Windows?

Thank you again.

Terry