Dieses Forum nutzt Cookies
Dieses Forum verwendet Cookies, um deine Login-Informationen zu speichern, wenn du registriert bist, und deinen letzten Besuch, wenn du es nicht bist. Cookies sind kleine Textdokumente, die auf deinem Computer gespeichert werden. Die von diesem Forum gesetzten Cookies werden nur auf dieser Website verwendet und stellen kein Sicherheitsrisiko dar. Cookies aus diesem Forum speichern auch die spezifischen Themen, die du gelesen hast und wann du zum letzten Mal gelesen hast. Bitte bestätige, ob du diese Cookies akzeptierst oder ablehnst.

Ein Cookie wird in deinem Browser unabhängig von der Wahl gespeichert, um zu verhindern, dass dir diese Frage erneut gestellt wird. Du kannst deine Cookie-Einstellungen jederzeit über den Link in der Fußzeile ändern.

Aktuellste PDF öffnen
#1
Hallo,

ich habe einen Code, der die aktuellste Excel Datei in einem angegebenen Ordner öffnet.

Code:
"Dim strTmpFileNew As String
     Dim strTmpFile As String
     Dim strPath As String
     Dim StrTyp As String
     Dim datTime As Date
     On Error GoTo Fin
    
     '---------------------------------------------------------------
     strPath = "DATEIPFAD"
      StrTyp = "*.xlsx"
     
    '----------------------------------------------------------------
    
     strTmpFile = Dir$(strPath & StrTyp)
     strTmpFileNew = strTmpFile
     datTime = FileDateTime(strPath & strTmpFile)
     Do While strTmpFile <> ""
         If datTime < FileDateTime(strPath & strTmpFile) Then
             datTime = FileDateTime(strPath & strTmpFile)
             strTmpFileNew = strTmpFile
         End If
         strTmpFile = Dir$()
     Loop
     If strTmpFileNew <> "" Then Workbooks.Open strPath & strTmpFileNew
Fin:
     If Err.Number <> 0 Then MsgBox "...………….", vbInformation, "......" "

Meine Frage ist nun, ob ich diesen Code auch für PDF's nutzen kann. Ich habe den StrTyp schon angepasst, allerdings weiß ich nicht was ich statt "Workbooks.Open" schreiben soll.
Oder ist das ganze nicht so einfach auf andere Dateien anwendbar.

MfG

Schmerich
Antworten Top
#2
Hallo, :19:

ganz oben (direkt nach Option Explicit) in dem Modul: :21:

Code:
Private Declare PtrSafe 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 Const SW_MAXIMIZE = 3

Und dann statt:

Code:
If strTmpFileNew <> "" Then Workbooks.Open strPath & strTmpFileNew


Das hier (getestet!):

Code:
If strTmpFileNew <> "" Then ShellExecute 0, "Open", strPath & strTmpFileNew, "", "", SW_MAXIMIZE
________
Servus
Case
Antworten Top
#3
Danke erstmal für die Antwort. Was genau meinst du mit dem ersten Teil?

Code sieht jetzt so aus:


Code:
"Sub AKT()
Private Declare PtrSafe 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 Const SW_MAXIMIZE = 3
Dim strTmpFileNew As String
     Dim strTmpFile As String
     Dim strPath As String
     Dim StrTyp As String
     Dim datTime As Date
     On Error GoTo Fin
    
     '---------------------------------------------------------------
     strPath = "DATEIPFAD" ' Pfadabgabe anpassen!!!
      StrTyp = "*.pdf" 'Dateiendung anpassen!!!
     
    '----------------------------------------------------------------
    
     strTmpFile = Dir$(strPath & StrTyp)
     strTmpFileNew = strTmpFile
     datTime = FileDateTime(strPath & strTmpFile)
     Do While strTmpFile <> ""
         If datTime < FileDateTime(strPath & strTmpFile) Then
             datTime = FileDateTime(strPath & strTmpFile)
             strTmpFileNew = strTmpFile
         End If
         strTmpFile = Dir$()
     Loop
     If strTmpFileNew <> "" Then ShellExecute 0, "Open", strPath & strTmpFileNew, "", "", SW_MAXIMIZE
Fin:
     If Err.Number <> 0 Then MsgBox "...…………...", vbInformation, "....."
End Sub"
Antworten Top
#4
Hallo, :19:

nein, die API - Deklaration muss außerhalb!

Code:
Option Explicit
Private Declare PtrSafe 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 Const SW_MAXIMIZE = 3
Sub Akt()
    Dim strPath As String
    Dim StrTyp As String
    Dim datTime As Date
    '.........
    '.........
    '.........
    If strTmpFileNew <> "" Then ShellExecute 0, "Open", strPath & strTmpFileNew, "", "", SW_MAXIMIZE
Fin:
    If Err.Number <> 0 Then MsgBox "Error: " & Err.Number & " " & Err.Description
End Sub

Statt der "'........." eben dein Code.
________
Servus
Case
Antworten Top
#5
Oder:

Code:
Sub M_snb()
    Shell "cmd /c " & "G:\OF\" & Split(CreateObject("wscript.shell").exec("cmd /c dir G:\OF\*.pdf /b/o-d").stdout.readall, vbCrLf)(0)
End Sub
Pfad 'G:\OF\ ' anpassen ( 2 x )
Zum übersetzen von Excel Formeln:

http://dolf.trieschnigg.nl/excel/index.p...gids=en+de
Antworten Top
#6
Sauber es funktioniert! Danke!!!
Antworten Top


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste