Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1244to1248
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

PDF dateien öffen

PDF dateien öffen
DirkR
Hallo Excelgemeinde,
vorab an alle im Forum ein frohes neues Jahr.
Ich habe folgendes Problem und komme da einfach nicht weiter:
Ich möchte alle pdf dateien in einem Verzeichnis inkl. Unterverzeichnis öffnen und/ oder drucken.
Bei dem Code unten funktioniert das mit einer PDF Datei schon ganz gut. Aber alle Dateien im Verz. bekomme ich einfach nicht hin.
Ich hoffe auf eure Hilfe!!!
Danke schon mal im Voraus!!!
Option Explicit
Public 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
Public Const SW_MAXIMIZE = 3      ' Maximiert öffnen
Public Const SW_MINIMIZE = 6      ' Minimiert öffnen
Public Const SW_NORMAL = 1

Sub PrintFile()
Dim strPfad As String
'Pfad zur Datei anpassen
strPfad = "C:\Users\Dirk\Desktop\Testordner PDF\Datei 1 Testordner.pdf"
'"print" = drucken; "open" = öffnen
Call ShellExecute(0, "print", strPfad, "", "", SW_MINIMIZE)
End Sub

Sub OpenFile()
Dim strPfad As String
'Pfad zur Datei anpassen
strPfad = "C:\Users\Dirk\Desktop\Testordner PDF\Datei 1 Testordner.pdf"
'"print" = drucken; "open" = öffnen
Call ShellExecute(0, "open", strPfad, "", "", SW_MINIMIZE)
End Sub

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: PDF dateien öffen
01.01.2012 20:54:11
Josef

Hallo Dirk,
das geht z. B. so.
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Public 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

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Const SW_MAXIMIZE = 3 ' Maximiert öffnen
Public Const SW_MINIMIZE = 6 ' Minimiert öffnen
Public Const SW_NORMAL = 1

Sub PrintFile()
  Dim strPath As String, strFile As String
  
  'Verzeichnis anpassen
  strPath = "C:\Users\Dirk\Desktop\Testordner PDF"
  
  If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
  
  strFile = Dir(strPath & "*.pdf", vbNormal)
  
  Do While strFile <> ""
    Call ShellExecute(0, "print", strPath & strFile, "", "", SW_MINIMIZE)
    Sleep 1000
    strFile = Dir
  Loop
  
End Sub

Sub OpenFile()
  Dim strPath As String, strFile As String
  
  'Verzeichnis anpassen
  strPath = "C:\Users\Dirk\Desktop\Testordner PDF"
  
  If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
  
  strFile = Dir(strPath & "*.pdf", vbNormal)
  
  Do While strFile <> ""
    Call ShellExecute(0, "open", strPath & strFile, "", "", SW_MINIMIZE)
    Sleep 500
    strFile = Dir
  Loop
  
End Sub



« Gruß Sepp »

Anzeige
AW: PDF dateien öffen
02.01.2012 10:19:45
DirkR
Hallo Sepp,
vielen Dank für deine Antwort!!!!
Funktioniert so weit super. Allerdings öffnen sich nicht die PDF-Dateien in den Unterverzeichnissen. Wie kann ich das noch realisieren?
Gruß DirkR
AW: PDF dateien öffen
02.01.2012 10:31:33
Josef

Hallo Dirk,
sorry, das mit den Unterordnern hatte ich übersehen.
' **********************************************************************
' Modul: Modul2 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Public 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

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Const SW_MAXIMIZE = 3 ' Maximiert öffnen
Public Const SW_MINIMIZE = 6 ' Minimiert öffnen
Public Const SW_NORMAL = 1

Sub PrintFile()
  Dim objFiles() As Object
  Dim lngIndex As Long, lngRes As Long
  Dim strPath As String, strFile As String
  
  'Verzeichnis anpassen
  strPath = "C:\Users\Dirk\Desktop\Testordner PDF"
  
  lngRes = FileSearchINFO(objFiles, strPath, "*.pdf", True)
  
  If lngRes > 0 Then
    For lngIndex = 0 To UBound(objFiles)
      Call ShellExecute(0, "print", objFiles(lngIndex).Path, "", "", SW_MINIMIZE)
      Sleep 1000
    Next
  End If
  
End Sub


Sub OpenFile()
  Dim objFiles() As Object
  Dim lngIndex As Long, lngRes As Long
  Dim strPath As String, strFile As String
  
  'Verzeichnis anpassen
  strPath = "C:\Users\Dirk\Desktop\Testordner PDF"
  
  lngRes = FileSearchINFO(objFiles, strPath, "*.pdf", True)
  
  If lngRes > 0 Then
    For lngIndex = 0 To UBound(objFiles)
      Call ShellExecute(0, "open", objFiles(lngIndex).Path, "", "", SW_MINIMIZE)
      Sleep 500
    Next
  End If
  
End Sub


Private Function FileSearchINFO(ByRef Files() As Object, ByVal InitialPath As String, Optional ByVal FileName As String = "*", _
    Optional ByVal SubFolders As Boolean = False) As Long

  
  '# PARAMETERINFO:
  '# Files: Datenfeld zur Ausgabe der Suchergebnisse
  '# InitialPath: String der das zu durchsuchende Verzeichnis angibt
  '# FileName: String der den gesuchten Dateityp oder Dateinamen enthält (Optional, Standard="*.*" findet alle Dateien)
  '# Beispiele: "*.txt" - Findet alle Textdateien
  '# "*name*" - Findet alle Dateien mit "name" im Dateinamen
  '# "*.avi;*.mpg" - Findet .avi und .mpg Dateien (Dateitypen mit ; trennen)
  '# SubFolders: Boolean gibt an, ob Unterordner durchsucht werden sollen (Optional, Standard=False)
  
  
  Dim fobjFSO As Object, ffsoFolder As Object, ffsoSubFolder As Object, ffsoFile As Object
  Dim intC As Integer, varFiles As Variant
  
  Set fobjFSO = CreateObject("Scripting.FileSystemObject")
  
  Set ffsoFolder = fobjFSO.GetFolder(InitialPath)
  
  On Error GoTo ErrExit
  
  If InStr(1, FileName, ";") > 0 Then
    varFiles = Split(FileName, ";")
  Else
    Redim varFiles(0)
    varFiles(0) = FileName
  End If
  For Each ffsoFile In ffsoFolder.Files
    If Not ffsoFile Is Nothing Then
      For intC = 0 To UBound(varFiles)
        If LCase(fobjFSO.GetFileName(ffsoFile)) Like LCase(varFiles(intC)) Then
          If IsArray(Files) Then
            Redim Preserve Files(UBound(Files) + 1)
          Else
            Redim Files(0)
          End If
          Set Files(UBound(Files)) = ffsoFile
          Exit For
        End If
      Next
    End If
  Next
  
  If SubFolders Then
    For Each ffsoSubFolder In ffsoFolder.SubFolders
      FileSearchINFO Files, ffsoSubFolder, FileName, SubFolders
    Next
  End If
  
  If IsArray(Files) Then FileSearchINFO = UBound(Files) + 1
  ErrExit:
  Set fobjFSO = Nothing
  Set ffsoFolder = Nothing
End Function



« Gruß Sepp »

Anzeige
AW: PDF dateien öffen
02.01.2012 10:41:01
DirkR
Hallo Sepp,
fantastisch, vielen vielen Dank Sepp!!!!
Es funktioniert super!!!!!!!!
Gruß DirkR

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige