Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1928to1932
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

OneDrive Local Pfad

OneDrive Local Pfad
10.05.2023 09:56:15
Theo

Hallo zusamme,

nachdem unsere Firma die Einstellungen für OneDrive für manche User geändert hat, können viele User leider nicht mehr "File Collaboration" ausschalten (in alten Versionen hiess das noch "Use Office applications to sync Office files that I open".
Als Folge liefert ThisWorkbook.Path nicht mehr:"C:\Users\Tiger.t\OneDrive - BesteFirma\Documents\TheoTools\HMF"
sondern stattdessen
"https://pgone-my.sharepoint.com/personal/tiger_t_bestefirma_com/Documents/Documents/TheoTools/HMF"

Im Forenarchiv habe ich gefunden, dass GetAbsolutePathName helfen soll, hier wird aber der Pfad irgendwie random abgeschnitten - er ignoriert die Subfolder:

Sub OneDrivePath()
    Dim fso As Object
    Dim HTTPPath As String
    Dim LocalPath As String
  
    Set fso = CreateObject("Scripting.FileSystemObject")
    HTTPPath = ThisWorkbook.Path
    
    'local Path sollte sein:
    '"C:\Users\Tiger.t\OneDrive - BesteFirma\Documents\TheoTools\HMF"
    LocalPath = fso.GetAbsolutePathName(ThisWorkbook.Name)
    'LocalPath ist:
   '"C:\Users\tiger.t\OneDrive - BesteFirma\Documents\DiesesTool.xlsb"
End Sub


ich habe auf Github schon die GetLocalPath Funktion gefunden, aber bei manchen Usern funktioniert die nicht :-(.

Hat noch jemand eine Idee?

Danke!

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: OneDrive Local Pfad
10.05.2023 10:11:57
RPP63
Moin!
Lasse Dir mal
Environ("Onedrive")
ausgeben.

Gruß Ralf


AW: OneDrive Local Pfad
10.05.2023 10:45:27
Theo
environ("onedrive") gibt mir den Höchsten Ordner aus, also:
C:\Users\tiger.t\OneDrive - BesteFirma

Ich suche aber nach dem aktuellen Subfolder (also C:\Users\Tiger.t\OneDrive - BesteFirma\Documents\TheoTools\HMF


AW: OneDrive Local Pfad
10.05.2023 11:12:27
RPP63
Zumindest bei mir funktioniert:
Sub Test()
Dim Arr, i&, Pfad$
Pfad = Environ("onedrive") & "\"
Arr = Split(ThisWorkbook.Path, "/")
For i = 4 To UBound(Arr)
  Pfad = Pfad & Arr(i) & "\"
Next
Debug.Print Pfad
End Sub


Anzeige
AW: OneDrive Local Pfad
10.05.2023 11:31:38
Theo
in der Richtung hatte ich auch schon gedacht, aber bei mir funzt das schon nicht, und ich befürchte bei anderen Usern wird das auch nicht funzen. Bei mir kommt dieser Pfad raus:
C:\Users\tiger.t\OneDrive - BesteFirma\tiger_t_bestefirm_com\Documents\Documents\theoTools\HMF\

Also werde ich vermutlich den Pfad aus dem Link "bauen" müssen.


AW: OneDrive Local Pfad
10.05.2023 15:01:28
Theo
Ich habe jetzt eine Lösung gebastelt, die zumindest für meinen Anwendungszweck funktioniert. Für den Fall, dass irgenwann mal jemand über das gleiche Problem stolpert:
Aufruf zb durch LocalPath = GetLocalPathSimple(ThisWorkbook)

Function GetLocalPathSimple(Wb As Workbook) As String
    '----------------------------------------------------------------------------------------------
    '--- Try to determine the local Folder using a simplified logic - probably does not work everywhere
    '--- It should work for subfolders of the MyDocument folders
    '----------------------------------------------------------------------------------------------
    Dim SubFolderStr As String
    Dim SubfolderStartDigit As Integer
    If MyDocPath = Empty Then
        MyDocPath = FindMyDocuments
    End If
    If InStr(1, Wb.Path, "Documents") > 0 Then
        '----------------------------------------------------------------------------------------------
        '--- find first backslash after documents
        '----------------------------------------------------------------------------------------------
        SubfolderStartDigit = InStrRev(Wb.Path, "Documents/")
        If SubfolderStartDigit > 0 Then
            '----------------------------------------------------------------------------------------------
            '--- Use everything behind "Documents/" as a subfolder
            '----------------------------------------------------------------------------------------------
            SubFolderStr = Mid(Wb.Path, SubfolderStartDigit + Len("Documents/"))
        
            '----------------------------------------------------------------------------------------------
            '--- Replace "/" with Backslash
            '----------------------------------------------------------------------------------------------
            SubFolderStr = Replace(SubFolderStr, "/", "\")
        
            '----------------------------------------------------------------------------------------------
            '--- Check if the new "calculated" Folder even exists
            '----------------------------------------------------------------------------------------------
            If CreateObject("Scripting.FileSystemObject").FolderExists(MyDocPath & "\" & SubFolderStr) Then
        
                '----------------------------------------------------------------------------------------------
                '--- Check if this file is indeed present in the folder
                '----------------------------------------------------------------------------------------------
                If Dir(MyDocPath & "\" & SubFolderStr & "\" & Wb.Name) > "" Then
                    '----------------------------------------------------------------------------------------------
                    '--- The calculated folder seems to be correct!
                    '----------------------------------------------------------------------------------------------
                    GetLocalPathSimple = MyDocPath & "\" & SubFolderStr
                End If
            End If
        End If
    End If
End Function

Function FindMyDocuments() As String
    'This Function will determine the path of the MyDocuments folder

    Dim WSH As Object                            'Windows Scripting Host
    Set WSH = CreateObject("WScript.Shell")
    FindMyDocuments = WSH.SpecialFolders("MyDocuments")
    Set WSH = Nothing
End Function

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige