How to save Libreoffice calc spreadsheet in 2 locations

I recently moved from Excel to Libreoffice and want to include a macro to save a file in two different locations. The
macro that I used in Excel was this:

Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub Save3Places()
chDir1 = "/home/Desktop/Docs/"
chDir2 = "/home/Destop/2021-Docs/"
Filename = "gastos.ods"
ActiveWorkbook.SaveAs Filename:=chDir1 + Filename
ActiveWorkbook.SaveAs Filename:=chDir2 + Filename
End Sub

The problem is that Libreoffice does not save this macro.

What would be the equivalent macro in Libreoffice calc?
Thanks in advance for your help.
Sarah.

(macro reformatted as source code by ajlittoz)

1 Like

A quick search on the Extensions page brought up some hits but only Timestamp Backup seemed to fit the requirements. There appears to be a question mark over whether it works in current versions.

BTW. In Windows Desktop is a bad place to save files. In the event of using System Restore you might not get your files on desktop back again; files in Documents are not affected by system restore

I should have said: I’m using Linux Mint (not Windows) on a computer with only Linux. I’m not too worried about the files as they are synced to the cloud.

I did wonder if you were on Linux or if home was a user name in Windows.

It looks as though you might have to have a look through some macro guides yourself, Andrew Pityonak’s book is useful. Chapter 13 of Getting Started 6.4 gives an overview of macros.

Maybe, question 75415 Macro save as xls can give you a clue as to some of the answer

Just in case anyone is interested, here is the solution I found for saving an .ods spreadsheet in 3 different locations:

sub Save3Places
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)

rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = “URL”
args1(0).Value = “file:///home/Desktop/Important/spreadsheet.ods”
args1(1).Name = “FilterName”
args1(1).Value = “calc8”

dispatcher.executeDispatch(document, “.uno:SaveAs”, “”, 0, args1())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = “URL”
args2(0).Value = “file:///home/Desktop/Documents/spreadsheet.ods”
args2(1).Name = “FilterName”
args2(1).Value = “calc8”

dispatcher.executeDispatch(document, “.uno:SaveAs”, “”, 0, args2())

rem ----------------------------------------------------------------------
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = “URL”
args3(0).Value = “file:///home/Desktop/Warpinator/spreadsheet.ods”
args3(1).Name = “FilterName”
args3(1).Value = “calc8”

dispatcher.executeDispatch(document, “.uno:SaveAs”, “”, 0, args3())

end sub