mit einer Api Funktion
05.03.2009 14:08:49
Tino
Hallo,
habe etwas gefunden mittels Api.
Versuche es mal so, nicht ausgiebig getestet.
'Benötigte Konstanten
Private Const MAX_PATH = 260
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_NORMAL = &H80
'API-Funktion deklarieren
Private Declare Function apiPathRelativePathTo Lib "shlwapi.dll" _
Alias "PathRelativePathToA" (ByVal pszPath As String, _
ByVal pszFrom As String, ByVal dwAttrFrom As Long, _
ByVal pszTo As String, ByVal dwAttrTo As Long) As Long
Public Function GetRelativePath(PathFrom As String, PathTo As String) As String
Dim pszPath As String
pszPath = Space(MAX_PATH)
'API-Funktion aufrufen
apiPathRelativePathTo pszPath, PathFrom, _
FILE_ATTRIBUTE_DIRECTORY, PathTo, FILE_ATTRIBUTE_NORMAL
'Rückgabe des relativierten Pfads
GetRelativePath = Left$(pszPath, InStr(pszPath, Chr(0)) - 1)
End Function
Sub Test()
Dim sPathGrund As String
Dim DateiName As String
Dim sPath As String
Dim sHyperlink As String
sPath = ThisWorkbook.Path
DateiName = Application.GetOpenFilename
sHyperlink = GetRelativePath(sPath, DateiName)
ActiveSheet.Hyperlinks.Add Anchor:=ActiveCell, Address:=sHyperlink, ScreenTip:="Gehe zu Verwenderhinweis"
End Sub
Gruß Tino