macros are sometimes weird, we’d construct a macro to do something similar - and more, saving a timestamped copy - i think you can use some parts of it … specially from the end where the file is reopened,
sub schliessenoeffnen ' *******************************br 26.09.2019
Dim oDoc, oForm, oblatt, oDatei as Object
' remember file
odoc = thiscomponent
speicherOrt = ConvertFromUrl(odoc.getLocation)
' strip if timestamped, apply new timestamp, save
extens = Right(speicherort,4)
dateilen = len(speicherort)-4
dateibase = left(speicherort, len(speicherort)-4)
tail = right(dateibase,17)
tlen = Len(Tail)
pos1 = instr(tail,"_")
pos2 = instr(tail,"-")
if pos1 > 0 and pos2 > 0 then
if pos1+ 5 <> pos2 then
notimestamp = true
else
if Mid(tail, pos1+ 11, 1) <> "_" or Mid(tail, pos1+ 8, 1) <> "-" or Mid(tail, pos1+ 14, 1) <> "-" then
notimestamp = true
else
dateibase = left(dateibase,len(Dateibase)-tlen) 'strip old timestamp
end if
end if
dateibase = dateibase & "_" & Format(Now(),"YYYY-MM-DD") & "_" & format(time(),"HH-MM" 'add new timestamp
else
dateibase = dateibase & "_" & Format(Now(),"YYYY-MM-DD") & "_" & format(time(),"HH-MM"
end if
fname = dateibase & extens
surl = converttourl(fname)
dim dummy()
odoc.storeasurl(surl,dummy())
' Formular schliessen
oDoc = thisComponent.currentController.frame
oDispatch = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatch.executeDispatch(oDoc, ".uno:CloseDoc", "", 0, Array())
' Formular öffnen
DIM sDatei, sPfad as string
oDoc = ThisComponent
sDatei = fname
sUrl_1 = ConvertToURL(sDatei) 'Umwandeln URL
sPfad = "scalc.exe" 'Pfad der zu verwendenden Applkation
Shell(sPfad + " " + sDatei,3) 'nun öffnen der Datei mit dem angegebenen Programm
end sub 'schliessenoeffnen ' *******************************br 26.09.2019
hope it helps, some comments are in german, sorry, deepl may help …