Save with name from a cell

hi,

I’d like to have in my spreadsheets (i use a model to create ten/twenty new spreadsheet a day) a button that can activate a macro to save the file in a specific folder, with the file name as the content of a certain cell.
will it be possible? and above all, how???

thanks yo for your help
Luca

“will it be possible? and above all, how???”

Yes it is possible by a custom macro. I suggest you to read Andrew Pitonyak’s free macro books.

[www.pitonyak.org/oo.php]

with the file name as the content of a certain cell

The ever same cell changing its value (by edit, by selction from a selection list,…) or certain cell (column) for a certain file?

An example file with exactly you want, help to who want help you.

First version.

Sub save_file()
	CELL_NAME = "A1"
	FOLDER = "/home/mau/"

	doc = ThisComponent
	sheet = doc.CurrentController.ActiveSheet
	cell = sheet.getCellRangeByName(CELL_NAME)
	
	path = ConvertToURL(FOLDER + cell.String + ".ods")
	
	doc.storeToURL(path, Array())
	
	MsgBox "Save in: " + path
End Sub

Hello @mauricio, interesting, this way does not remove the pending altered and unsaved file, and accepts to delete the file with it open.

You must learn about the difference of the StoreToURL() and the StoreAsURL() methods.

And you must check (by some commands) if a file exists with same file name on same path or not exist…

Unfortunately, in generally, users in this forum, give us very little information that really want make.

Hola @mauricio, pido ayuda para cambiar tu macro para poder indicar la hoja por nombre

Sub save_fileX
	PLAN_NAME = "Plan1"
    CELL_NAME = "A1"
    FOLDER = "C:\Users\GILBERTO\Desktop\"

    doc = ThisComponent
'    sheet = doc.CurrentController.ActiveSheet
    sheet = doc.getSheetByName(PLAN_NAME)    '<=== ERRO 
    cell = sheet.getCellRangeByName(CELL_NAME)

    path = ConvertToURL(FOLDER + cell.String + ".ods")

    doc.storeToURL(path, Array())

    MsgBox "Save in: " + path
End Sub

Agradecido

sheet = doc.Sheets.getByName(PLAN_NAME)

https://wiki.documentfoundation.org/Macros/Basic/Calc/Sheets#Get_by_name

Muchas gracias

tanks for your help … very well done!
thanks again
Luca