Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Otvaranje fajlova ( Word, Excel, PDF...) kroz VBA

[es] :: Access :: Otvaranje fajlova ( Word, Excel, PDF...) kroz VBA

[ Pregleda: 1910 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Zidar
Canada

Moderator
Član broj: 15387
Poruke: 3085
*.100.46-69.q9.net.



+79 Profil

icon Otvaranje fajlova ( Word, Excel, PDF...) kroz VBA02.02.2016. u 17:20 - pre 99 meseci
Na ovom linku sam nasao interesantno objasnjenje. Original je za Excel VBA, ali ima i resenje za Access VBA: http://www.erlandsendata.no/en...dex.php?d=envbafoldersfileopen

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



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
 
Odgovor na temu

3okc
Χoᴘᴦoѡ

Član broj: 811
Poruke: 1318

Jabber: 3okc@elitesecurity.org


+116 Profil

icon Re: Otvaranje fajlova ( Word, Excel, PDF...) kroz VBA03.02.2016. u 13:59 - pre 99 meseci
Ova f-ja GetExecutablePath, iz prethodnog koda, istražuje da li postoji aplikacija (pred)određena da otvori konkretan fajl - pdf čitač, u ovom slučaju.

Jedan drugi metod, maksimalno pojednostavljen, otvara zamišljeni pdf na putanji samog Excel-dokumenta, iz kog se procedura i pokreće:

Code:

Sub OpenPdf()
' Pdf čitač mora da postoji inače javlja grešku

    On Error GoTo ErrPdf
    ActiveWorkbook.FollowHyperlink _
        ThisWorkbook.Path & "\Uputstvo A.pdf", NewWindow:=True
    Exit Sub
ErrPdf:    MsgBox Err.Description
End Sub

Have you found helpful examples, solutions or ideas-in-work, please consider the
following:
• Citation of *actual page* you are going to using is welcome.
• Have you saw "Value Added" examples you are going to incorporate to your
profitable blog, daily job or any money making venture: How about online donation?
↗Ana & Vlade Divac Foundation
Hvala!
 
Odgovor na temu

Zidar
Canada

Moderator
Član broj: 15387
Poruke: 3085
*.100.46-69.q9.net.



+79 Profil

icon Re: Otvaranje fajlova ( Word, Excel, PDF...) kroz VBA03.02.2016. u 16:26 - pre 99 meseci
Zahvaljuje @3okc! :-)
 
Odgovor na temu

[es] :: Access :: Otvaranje fajlova ( Word, Excel, PDF...) kroz VBA

[ Pregleda: 1910 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.