LibreOffice Writer macro code samples

Current file name, directory and full path

with help from a question I asked at https://ask.libreoffice.org/t/macro-function-regex-not-working/97425

Sub CurrentFileLocation
	sUrl = ThisComponent.getURL()
	
	'To get the full path
	sFullPath = ConvertFromURL(sUrl)
	
	'Then to get the full path but no the file name
	sParts = Split(sFullPath,"\")
	ReDim Preserve sParts(0 to UBound(sParts) - 1)
	 sDirectory = Join(sParts, "/")
	 
	'Then to get just the document name
	sParts = split(sUrl,"/")
	sName =convertfromurl(sParts(ubound(sParts)))
	'ubound returns the last item in the array sParts
	
	'Then to see the results
	msgbox(sName & Chr$(13) & sDirectory & Chr$(13) & sFullPath )
end sub

 

Comments are closed.