2017-12-13 16 views
1

를 사용하여 경로를 가져올 때 오류를 얻기, 나는 다음과 같은 매크로 코드를 건너 왔어요 파일을 닫은 다음 다시 엽니 다. 이 오류는 도구 매크로 라이브러리 내에서 다음 함수의 마지막 줄에 생성되는LibreOffice와 캘크 셀에 파일의 현재 경로를 얻기에 해결책을 온라인으로 검색 한 후 매크로

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 

는 잘 모르겠어요.

아이디어가 있으십니까? 감사.

+0

경우'ArrayoutofString'의 코드는? –

+0

그 기능에 대한 코드를 원래 게시물 –

+0

에 추가했습니다. 디버그 한 다음 'SepList()'에 내용이 있습니까? 오류가있을 때'i'의 값은 무엇입니까? –

답변

1

더 좋은 방법이 있습니다.

=LEFT(CELL("filename");FIND("#$";CELL("filename"))-1) 

출처 : 세포 기능에 https://ask.libreoffice.org/en/question/67271/how-to-automatically-display-file-path-in-a-cell/ 문서 :

https://help.libreoffice.org/Calc/Information_Functions#CELL는 또한, 매크로와 함께 수행 View created 이벤트를 실행하려면 다음 WritePath 서브 루틴을 할당합니다.

function GetPath() as string 
    On Error Goto ErrorHandler 
    GlobalScope.BasicLibraries.loadLibrary("Tools") 
    GetPath = Tools.Strings.DirectoryNameoutofPath(ThisComponent.url, "/") 
    ErrorHandler: 
end function 

Sub WritePath 
    oSheet = ThisComponent.getSheets().getByIndex(0) 
    oCell = oSheet.getCellRangeByName("A1") 
    oCell.setString(GetPath()) 
End Sub 

매크로 솔루션의 작동 방식과 문제에 대한 설명은 https://stackoverflow.com/a/39254907/5100564을 참조하십시오.

편집는 :

다음 표현식은 파일 이름없이 경로를 제공합니다. 이 기능을 사용하려면 도구 -> 옵션 -> LibreOffice Calc -> 계산 아래의 수식에서 정규식을 사용하도록 설정해야합니다.

=MID(CELL("filename");2;SEARCH("/[^/]*$";CELL("filename"))-1) 

https://wiki.openoffice.org/wiki/Documentation/How_Tos/Regular_Expressions_in_Writer

+0

나는 그걸 보지 못했습니다. 그러나, 그것은 저에게 파일 이름을 포함하여 전체 경로를 제공합니다. 난 그저 들어있는 디렉토리까지 경로를 원한다. –

+1

@Lee Blake : 편집 된 답변 참조. –

+0

완벽하게 작동합니다! 그런 철저한 대답에 감사드립니다. 이 문제를 해결했을뿐만 아니라 왜 지금 작동하지 않는지 이해합니다. –