AW: Öffnen PDF-Dateien über Excel-Hyperlinks ?
28.08.2005 11:53:48
Nepumuk
Hi Selma,
du machst nichts falsch. Das selbe passiert bei mir auch. Wir können das aber abfangen. Rechtsklick auf das Excelicon neben "Datei" - Code anzeigen. Folgendes Makro einfügen:
' **********************************************************************
' Modul: DieseArbeitsmappe Typ: Element der Mappe(Sheet, Workbook, ...)
' **********************************************************************
Option Explicit
Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
Private Const MAX_PATH = 260&
Private Const SW_MAXIMIZE = 3&
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
Dim strPath As String, strShortPath As String, strFile As String
If LCase$(Right$(Target.Name, 3)) = "pdf" Then
strFile = Right$(Target.Name, InStr(1, StrReverse(Target.Name), "\") - 1)
strPath = Left$(Target.Name, Len(Target.Name) - Len(strFile))
strShortPath = Space(MAX_PATH)
GetShortPathName strPath & strFile, strShortPath, MAX_PATH
strShortPath = Left$(strShortPath, InStr(1, strShortPath, vbNullChar) - 1)
ShellExecute GetActiveWindow, "open", strShortPath, vbNullString, strPath, SW_MAXIMIZE
End If
End Sub
Gruß
Nepumuk
Excel & VBA Beispiele