【发布时间】:2017-12-13 21:34:26
【问题描述】:
在网上搜索将文件的当前路径放入 LibreOffice Calc 单元格的解决方案后,我发现了以下宏代码:
function GetPath() as string
GlobalScope.BasicLibraries.loadLibrary("Tools")
GetPath = Tools.Strings.DirectoryNameoutofPath(ThisComponent.url, "/")
end function
这一直有效,直到我关闭文件,然后重新打开它。当我重新打开它时,我收到以下错误消息:
Inadmissible value or data type.
Index out of defined range.
此错误是在工具宏库中以下函数的最后一行产生的。
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
那个函数的代码是……
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
我不确定为什么这会在文件加载时产生错误,但之后继续工作。
有什么想法吗?谢谢。
【问题讨论】:
-
ArrayoutofString的代码在哪里? -
我已将该函数的代码添加到原帖中
-
如果您调试,那么
SepList()中是否有内容?i出错时的值是多少? -
经过进一步调查,似乎它只在文件加载期间产生错误。文件加载后,我可以毫无问题地使用上述功能。我想知道这是否与时间有关。
标签: vba path libreoffice-calc