Access resenje (cut/paste sa linka, nisam testirao niti probao):
Code:
' -- Otvorite novi modul i ovo stavite na pocetak:
Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Declare Function FindExecutable Lib "shell32.dll" _
Alias "FindExecutableA" (ByVal lpFile As String, _
ByVal lpDirectory As String, ByVal lpResult As String) As Long
' -- Onda dodajte ovo ispod deklaracija:
Function GetExecutablePath(strFileType As String) As String
' returns the full path to the executable associated with the given file type
Dim strFileName As String, f As Integer, strExecutable As String, r As Long
If Len(strFileType) = 0 Then Exit Function ' no file type
strFileName = String$(255, " ")
strExecutable = String$(255, " ")
GetTempFileName CurDir, "", 0&, strFileName ' get a temporary file name
strFileName = Trim(strFileName)
strFileName = Left$(strFileName, Len(strFileName) - 3) & strFileType ' add the given file type
f = FreeFile
Open strFileName For Output As #f ' create the temporary file
Close #f
r = FindExecutable(strFileName, vbNullString, strExecutable) ' look for an associated executable
Kill strFileName ' remove the temporary file
If r > 32 Then ' associated executable found
strExecutable = Left$(strExecutable, InStr(strExecutable, Chr(0)) - 1)
Else ' no associated executable found
strExecutable = vbNullString
End If
GetExecutablePath = strExecutable
End Function
' -- Otvorite novi modul i ovo stavite na pocetak:
Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Declare Function FindExecutable Lib "shell32.dll" _
Alias "FindExecutableA" (ByVal lpFile As String, _
ByVal lpDirectory As String, ByVal lpResult As String) As Long
' -- Onda dodajte ovo ispod deklaracija:
Function GetExecutablePath(strFileType As String) As String
' returns the full path to the executable associated with the given file type
Dim strFileName As String, f As Integer, strExecutable As String, r As Long
If Len(strFileType) = 0 Then Exit Function ' no file type
strFileName = String$(255, " ")
strExecutable = String$(255, " ")
GetTempFileName CurDir, "", 0&, strFileName ' get a temporary file name
strFileName = Trim(strFileName)
strFileName = Left$(strFileName, Len(strFileName) - 3) & strFileType ' add the given file type
f = FreeFile
Open strFileName For Output As #f ' create the temporary file
Close #f
r = FindExecutable(strFileName, vbNullString, strExecutable) ' look for an associated executable
Kill strFileName ' remove the temporary file
If r > 32 Then ' associated executable found
strExecutable = Left$(strExecutable, InStr(strExecutable, Chr(0)) - 1)
Else ' no associated executable found
strExecutable = vbNullString
End If
GetExecutablePath = strExecutable
End Function
Ovako se poziva, na primer za otvaranje PDF fajla:
Code:
Function OpenPDFDocument(MyFile)
Dim strDocument As String, strExecutable As String
strDocument = (MyFile)
If Len(strDocument) < 6 Then Exit Function
strExecutable = GetExecutablePath(".pdf") ' get the path to Acrobat Reader (or other file just change to .xls, .doc etc)
If Len(strExecutable) > 0 Then
Shell strExecutable & " " & strDocument, vbMaximizedFocus ' open pdf document
End If
End Function
Function OpenPDFDocument(MyFile)
Dim strDocument As String, strExecutable As String
strDocument = (MyFile)
If Len(strDocument) < 6 Then Exit Function
strExecutable = GetExecutablePath(".pdf") ' get the path to Acrobat Reader (or other file just change to .xls, .doc etc)
If Len(strExecutable) > 0 Then
Shell strExecutable & " " & strDocument, vbMaximizedFocus ' open pdf document
End If
End Function