how i display current file name only in open office 2.0 using macro (display on msg box)

how i display current file name in open office 2.0 using macro (display on msg box)

Hello,

sub CurrentFileLocation
    MsgBox ThisComponent.getLocation()
end sub

If this is run on a new unsaved document, the message will be empty. Works on different documents - i.e. Writer, Calc, etc.

Hi

Just be careful that ThisComponent is indeed a document (do not launch this procedure from a module of the My Maros Standard library, for example)

Regards

i want file name only (without path)

Since the document name is also in the document frame as a title you can use this:

MsgBox ThisComponent.Title

i want file name only (without path)

LibreOffice Macros & DialogTools library▸Strings module includes useful procedures such as FileNameoutofPath, GetFileNameExtension, GetFileNameWithoutExtension, DirectoryNameoutofPath, etc.

You can load & use the library with:

GlobalScope.BasicLibraries.LoadLibrary("Tools")

Regards

@PYS

Thank you. I seldom remember those are there.

sub CurrentFileLocation
MsgBox ThisComponent.getLocation()
end sub

MsgBox ThisComponent.Title

GlobalScope.BasicLibraries.LoadLibrary(“Tools”)

These are not functioning, i am using open office 2.0

Unfortunately that was not part of your original question. As this is a LibreOffice forum and that is a very old AOO version, it may be best to post your question on AOO Forum.

Hi This is not the right place indeed… However, the procedure as you copied it cannot work (even if the library existed in this version of OOo): instructions appear after the End Sub.

You should write something like:

sub CurrentFileLocation 

GlobalScope.BasicLibraries.LoadLibrary("Tools")
MsgBox FileNameoutofPath(ThisComponent.getLocation())

end sub

Regards

thanks its working.