AW: Datei nur von bestimmten Speicherort starten
29.05.2018 08:55:58
bestimmten
Hallo
du könntest dir den UNC- Pfad aus den jeweils "Lokalen Pfaden" ermitteln und den dann abgleichen.
z.B. mit folgender Function.
Private Declare Function WNetGetConnection Lib "mpr.dll" _
Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
cbRemoteName As Long) As Long
Public Function GetUNCPath(ByVal sLocalPath As String) As String
'// -----------------------------------------------------------------
'// Methode: | Konvertiert einen Pfad in UNC-Pfad (\\SERVER\...)
'// -----------------------------------------------------------------
'// Parameter: | sLocalPath = gültiger, lokaler Pfad (X:\..)
'// -----------------------------------------------------------------
'// Rückgabe: | bei Erfolg = UNC-Pfad
'// | bei Fehler = sLocalPath
'// -----------------------------------------------------------------
Const NO_ERROR As Long = 0
Dim sUNCPath As String
Dim sResult As String
Dim sDrive As String
GetUNCPath = sLocalPath
If VBA.Mid$(sLocalPath, 2, 1) <> ":" Then Exit Function
'// Die API-Funktion benötigt nur das Laufwerk!
sDrive = VBA.Left$(sLocalPath, 2)
sUNCPath = VBA.String(260, 0)
If WNetGetConnection(sDrive, sUNCPath, VBA.Len(sUNCPath)) = NO_ERROR Then
sResult = VBA.Left$(sUNCPath, VBA.InStr(sUNCPath, vbNullChar) - 1)
If VBA.Len(sResult) > 0 Then
GetUNCPath = sResult & VBA.Mid$(sLocalPath, 3)
End If
End If
End Function
Aufrufen z.B. so..
Sub HAllo()
Dim DerRichtigePfad As String
DerRichtigePfad = "\\Server\Freigabe\...\Test.xlsm"
If GetUNCPath(ThisWorkbook.FullName) = DerRichtigePfad Then
MsgBox "erlaubt"
Else
MsgBox "leider nein"
Exit Sub
End If
End Sub
LG UweD