After searching online for a solution to getting the current path of the file into a LibreOffice Calc cell, I came across the following macro code:
function GetPath() as string
GlobalScope.BasicLibraries.loadLibrary("Tools")
GetPath = Tools.Strings.DirectoryNameoutofPath(ThisComponent.url, "/")
end function
This works until I close the file, then re-open it. When I re-open it, I get the following error message:
Inadmissible value or data type.
Index out of defined range.
This error is generated on the last line of the following function within the Tools Macro library.
Function FileNameoutofPath(ByVal Path as String, Optional Separator as String) as String
Dim i as Integer
Dim SepList() as String
If IsMissing(Separator) Then
Path = ConvertFromUrl(Path)
Separator = GetPathSeparator()
End If
SepList() = ArrayoutofString(Path, Separator,i)
FileNameoutofPath = SepList(i)
End Function
The code for that function is...
Function ArrayOutOfString(BigString, Separator as String, Optional MaxIndex as Integer)
Dim LocList() as String
LocList=Split(BigString,Separator)
If not isMissing(MaxIndex) then maxIndex=ubound(LocList())
ArrayOutOfString=LocList
End Function
I'm not sure why this would generate an error on file load, but continue to work thereafter.
Any idea? Thanks.