add date to filename when saving?

classic Classic list List threaded Threaded
3 messages Options
Dave Stevens Dave Stevens
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

add date to filename when saving?

I can manually add today's date to a filename when using save as... but
would like to have LO writer do it for me. Anyone know how?

Dave


--
In modern fantasy (literary or governmental), killing people is the
usual solution to the so-called war between good and evil. My books are
not conceived in terms of such a war, and offer no simple answers to
simplistic questions.

----- Ursula Le Guin

--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

joomlafab joomlafab
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: add date to filename when saving?

This post has NOT been accepted by the mailing list yet.
Hi !
you certainly can do it with a macro, then add a button to your toolbar linked to that macro.
Here is a quick and dirty example.

function getDocType(oDoc) as string
	getDocType = ""
	if HasUnoInterfaces(oDoc, "com.sun.star.lang.XServiceInfo") then 
	   if thisComponent.supportsService ("com.sun.star.text.GenericTextDocument") then
	      getDocType = "odt"
	   elseif thisComponent.supportsService("com.sun.star.sheet.SpreadsheetDocument") then
	      getDocType = "ods"
	   REM to be continued...
	   end if
	end if
End function

Sub saveAsWithDate()
	Dim sDocExt As string
	Dim sFileName As String
	sDocExt = getDocType(thisComponent)
	
	if sDocType <> "" Then
		Dim oDialog As Object
		Dim iFS AS integer
		oDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
		oDialog.setDisplayDirectory(GetWorkDir())
		iFS = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE
		oDialog.initialize(Array(iFS))
		If oDialog.Execute() = 1 Then
			sPath = oDialog.Files(0)
		    Dim dDate As Date
		    Dim sDate As String
		    dDate = date
		    sDate = Format(dDate, "yyyy-mm-dd")
		    sFileName = sPath & "-" & sDate & "." & sDocExt
	      	If FileExists(sFileName) Then
				If MsgBox (sFileName & " already exists. Do you want to Overwrite ?",  260) = 7 Then
					MsgBox "File not saved"
					Exit Sub
				End if	      		
	      	End if
			thisComponent.StoreAsURL(ConvertToURL(sFileName),Array())
			MsgBox "File saved"
		End If
	Else
		MsgBox "Current file type unknown"
	End if	
End sub
Alex Thurgood Alex Thurgood
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: add date to filename when saving?

In reply to this post by Dave Stevens
Le 27/05/2017 à 17:42, Dave Stevens a écrit :

Hi Dave,


> I can manually add today's date to a filename when using save as... but
> would like to have LO writer do it for me. Anyone know how?

Not sure whether this is what you are looking for :

https://forum.openoffice.org/en/forum/viewtopic.php?f=20&p=203299


Alex



--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Loading...