Live-Forum - Die aktuellen Beiträge
Datum
Titel
24.04.2024 19:29:30
24.04.2024 18:49:56
Anzeige
Archiv - Navigation
632to636
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
632to636
632to636
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

PDF-File von Excel aus starten und ...

PDF-File von Excel aus starten und ...
07.07.2005 09:20:26
Excel
Hallo zusammen!
Brauche jetzt doch eure Hilfe, komme hier nicht ganz weiter.
Der folgende Code bewirkt, dass nach einer File / Files, deren Pfad in einer Zelle ("splitt.Offset(0, -10).Value") eingetragen ist, gesucht wird.
Das funktioniert auch einwandfrei.
Danach gehts weiter, dass Acrobat dann gestartet und anschließend das pdf geöffnet wird. Das klappt auch alles super.
Ich möchte bloß, dass nachdem Acrobat gestartet wurde und die pdf(s) geöffnet wurden, Excel wieder aktiviert wird, sprich in den Vordergrund rutscht, damit der Benutzer das Excel-Fenster wieder sieht. Aber genau das krieg ich irgendwie nicht hin! :-(
Was muss ich da noch hinzufügen?
Und noch was:
Gibts noch ne andere Möglichkeit Acrobat zu starten, ohne dass man den festen Pfad angeben muss? Denn das Programm befindet sich ja nicht auf jedem PC im gleichen Verzeichnis ...
Vielen Dank für eure Hilfe schonmal!
Gruss,
Michl

Sub test()
With ActiveSheet.Columns(20)
Set splitt = .Find("SplittFehler", LookIn:=xlValues, LookAt:=xlWhole)
If Not splitt Is Nothing Then
firstAddress = splitt.Address
Do
With splitt.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
With splitt.Offset(0, -10).Interior
.ColorIndex = 40
.Pattern = xlSolid
' Suche und öffne Datei
Set fs = Application.FileSearch
path = "D:\test\"
With fs
.LookIn = path
.SearchSubFolders = True
.Filename = splitt.Offset(0, -10).Value
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
File = .FoundFiles(i)
Shell Chr(34) & "C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe" & Chr(34) & _
Chr (34) & File & Chr(34), vbMaximizedFocus
Next i
Else
MsgBox "There were no files found."
End If
End With
End With
Set splitt = .FindNext(splitt)
Loop While Not splitt Is Nothing And splitt.Address <> firstAddress
End If
End With
End Sub

16
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: PDF-File von Excel aus starten und ...
07.07.2005 10:45:45
Excel
Hallo,
zu 2:
If .Execute() &gt 0 Then
Dim myShell As Object
Set myShell = CreateObject("WScript.Shell")
For i = 1 To .FoundFiles.Count
File = Chr(34) & .FoundFiles(i) & Chr(34)
myShell.Run File
Next i
Gruß
Geist ist geil!
AW: PDF-File von Excel aus starten und ...
07.07.2005 11:21:10
Excel
Hi u_
Vielen Dank, dieser Teil funktioniert nun auch prächtig dank dir! ;)
Aber könntest du mir evt. dies Zeile kurz erklären:
File = Chr(34) & .FoundFiles(i) & Chr(34)
Das mit dem Chr(34) versteh ich nicht, hab ich auch bei meinem ersten Beispiel nicht verstanden, habs einfach aus der Recherche kopiert. :-(
Und warum wird jetzt AcrobatReader automatisch gestartet? Sucht er irgendwie intern nach der exe erst oder wie?
Sry, peil ich grad nich ganz ...
Dank dir schonmal.
Anzeige
AW: PDF-File von Excel aus starten und ...
07.07.2005 11:21:52
Excel
noch offen ...
AW: PDF-File von Excel aus starten und ...
07.07.2005 12:09:44
Excel
Hallo,
Und warum wird jetzt AcrobatReader automatisch gestartet? Sucht er irgendwie intern nach der exe erst oder wie?
Wenn du eine Datei (egal welcher Typ) startest, wird immer die EXE ausgeführt.
Das gleiche passiert auch bei Doppelklick auf eine Datei.
Wenn du also eine PDF-Datei öffnest, weiss diese Datei, dass sie mit dem Adobe-Reader geöffnet werden soll.
Wenn du diese Datei mal mit der rechten Maustaste anklickst, kannst du sogar auswählen, mit welchem Programm sie geöffnet werden soll.
Gruß DieterB
AW: PDF-File von Excel aus starten und ...
07.07.2005 12:51:03
Excel
Hallo,
der Dateiname wird um " ergänzt. Aus Datei.xls wird somit "Datei.xls". Ist erforderlich für den Run-Befehl.
myShell verweist auf das Shell-Objekt des Windows-Scriptinghost. Der muss also aktiv sein. Hierdurch wird einfach die Anwendung gestartet, die dem Öffnen von .pdf zugewiesen ist.
Gruß
Geist ist geil!
Anzeige
AW: PDF-File von Excel aus starten und ...
07.07.2005 14:09:54
Excel
Ok, vielen Dank euch beiden!
Aber wie ich das Excel-Fenster wieder aktiviere, kann wir wahrscheinlich keiner sagen oder?
Mit AppActivate("Microsoft Excel") klappts nicht und das versteh ich nicht. Normalerweise funktioniert der Befehl immer. :-(
Woran liegt das?
Grüssle,
Michl
AW: PDF-File von Excel aus starten und ...
07.07.2005 17:09:32
Excel
Hi,
bei manchen Fenstern, die in Vordergrund sind , hilft nur rohe Gewalt:
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 SetWindowPos Lib "user32.dll" ( _
    ByVal hWnd As Long, _
    ByVal hWndInsertAfter As Long, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal wFlags As Long) As Long

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

Private Declare Sub Sleep Lib "kernel32.dll" ( _
    ByVal dwMilliseconds As Long)

Private Declare Function GetWindowPlacement Lib "user32" ( _
    ByVal hWnd As Long, _
    ByRef lpwndpl As WINDOWPLACEMENT) As Long

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type WINDOWPLACEMENT
    Length As Long
    flags As Long
    showCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type

Private Const MAX_PATH = 260&

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40

Private Const SW_MAX = 10&

Public Sub prcOpen_PDF()
    Dim strPath As String, strShortPath As String, strFile As String
    Dim hWnd As Long, WinEst As WINDOWPLACEMENT
    WinEst.Length = Len(WinEst)
    strFile = "bpl08827.pdf"
    strPath = "D:\Eigene Dateien\Eigene eBooks\"
    strShortPath = Space(MAX_PATH)
    GetShortPathName strPath & strFile, strShortPath, MAX_PATH
    ShellExecute FindWindow("XLMAIN", vbNullString), "open", strShortPath, "", strPath, SW_MAX
    Do
        Sleep 100
        hWnd = FindWindow("AdobeAcrobat", vbNullString)
        If hWnd <> 0 Then GetWindowPlacement hWnd, WinEst
        Debug.Print WinEst.showCmd
        If WinEst.showCmd = 3 Then Exit Do
    Loop
    SetWindowPos FindWindow("XLMAIN", vbNullString), HWND_TOPMOST, _
        0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
    SetWindowPos FindWindow("XLMAIN", vbNullString), HWND_NOTOPMOST, _
        0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub

Gruß
Nepumuk
Die Spezialisten
Anzeige
AW: PDF-File von Excel aus starten und ...
07.07.2005 17:11:10
Excel
Upps,
die Debug.Print Anweisung kannst du natürlich entfernen. Die war nur zum testen drin. :-)
Gruß
Nepumuk
Die Spezialisten
AW: PDF-File von Excel aus starten und ...
07.07.2005 22:42:37
Excel
Hallo,
echt heiß!
Gruß aus’m Pott
Udo

AW: PDF-File von Excel aus starten und ...
08.07.2005 10:35:56
Excel
Ok, danke, wenns nich anders geht, dann muss ich das wohl so machen. :-(
AW: PDF-File von Excel aus starten und ...
08.07.2005 12:16:45
Excel
Hallo nochmal!
Hab jetzt deinen Code abgeändert, so dass es für mich passt. Aber leider erhält das Excel-Fenster danach immer noch nicht den Fokus! Am Ende seh ich wieder nur Arcobat im Vordergrund ...
Schau doch bitte mal drüber, weiß nich worans liegt. :-(
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 SetWindowPos Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Declare 

Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare 

Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)
Private Declare 

Function GetWindowPlacement Lib "user32" ( _
ByVal hWnd As Long, _
ByRef lpwndpl As WINDOWPLACEMENT) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Const MAX_PATH = 260&
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const SW_MAX = 10&

Sub test()
Dim path As String
Dim leer As String
Dim myShell As Object
Dim strPath As String, strShortPath As String, strFile As String
Dim hWnd As Long, WinEst As WINDOWPLACEMENT
Dim lngrow
With ActiveSheet.Columns(20)
Set splitt = .Find("SplittFehler", LookIn:=xlValues, LookAt:=xlWhole)
n = 5
If Not splitt Is Nothing Then
firstAddress = splitt.Address
Do
With splitt.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
With splitt.Offset(0, -10).Interior
.ColorIndex = 40
.Pattern = xlSolid
' Suche und öffne Datei
Set fs = Application.FileSearch
path = "\\w71c-122623\Lw_d\Elast_Ordner\E090421_Bearbeitung\"
With fs
.LookIn = path
.SearchSubFolders = True
.Filename = splitt.Offset(0, -10).Value
If .Execute() > 0 Then
lngrow = ""
If lngrow < Cells(Range("J65536").End(xlUp).Row, 10) Then
Cells(Range("J65536").End(xlUp).Row + n, 10) = "Splitt-Fehler in Datei " & "'" & fs.Filename & "'" & " :"
Cells(Range("J65536").End(xlUp).Row + 1, 10) = "'" & " --> Fehlende Seiten: "
n = 2
End If
For i = 1 To .FoundFiles.Count
File = Chr(34) & .FoundFiles(i) & Chr(34)
ShellExecute FindWindow("XLMAIN", vbNullString), "open", File, "", "", SW_MAX
Do
Sleep 100
hWnd = FindWindow("AdobeAcrobat", vbNullString)
If hWnd <> 0 Then GetWindowPlacement hWnd, WinEst
Debug.Print WinEst.showCmd
If WinEst.showCmd = 3 Then Exit Do
Loop
SetWindowPos FindWindow("XLMAIN", vbNullString), HWND_TOPMOST, _
0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
SetWindowPos FindWindow("XLMAIN", vbNullString), HWND_NOTOPMOST, _
0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
Next i
Else
MsgBox "There were no files found."
End If
End With
End With
Set splitt = .FindNext(splitt)
Loop While Not splitt Is Nothing And splitt.Address <> firstAddress
End If
End With
End Sub

Anzeige
AW: PDF-File von Excel aus starten und ...
08.07.2005 20:52:32
Excel
Hi,
du musst den Part nach der ShellExecute - Funktion an das Ende deines Makros platzieren.
Gruß
Nepumuk
AW: PDF-File von Excel aus starten und ...
11.07.2005 10:36:34
Excel
Danke Nepumuk, werds mal ausprobieren ... :-)
AW: PDF-File von Excel aus starten und ...
12.07.2005 15:06:38
Excel
Hi Nepumuk!
Ich hab jetzt den Part nach ShellExecute ans Ende des Makros gesetzt, sprich vor End Sub.
Nur leider bringt das auch nichts. :-((
Komischerweise, nachdem die letzte pdf in Adobe geladen wurde, verschwindet "Microsoft Excel" aus der Taskleiste, erst wenn ich Adobe minimiere seh ich Excel wieder.
Hast du evt. ne Idee, warum des immer noch nich geht?
Dank dir schonmal!
Michl
AW: PDF-File von Excel aus starten und ...
12.07.2005 15:09:54
Excel
Hi Nepumuk!
Ich hab jetzt den Part nach ShellExecute ans Ende des Makros gesetzt, sprich vor End Sub.
Nur leider bringt das auch nichts. :-((
Komischerweise, nachdem die letzte pdf in Adobe geladen wurde, verschwindet "Microsoft Excel" aus der Taskleiste, erst wenn ich Adobe minimiere seh ich Excel wieder.
Hast du evt. ne Idee, warum des immer noch nich geht?
Dank dir schonmal!
Michl
Anzeige
AW: PDF-File von Excel aus starten und ...
12.07.2005 16:10:20
Excel
Servus,
ich habs mal getestet. Das funktioniert bei mir einwandfrei. Das einzige was ich von Reader sehe, ist das Startfenster. Ich musste den Code ein bisschen eindampfen, da ich die Tabelle nicht nachbauen will. Teste es mal mit der Version. Leg dazu eine Ornder mit zwei oder drei PDF's an und pass den Pfad im Filesearch an.
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 SetWindowPos Lib "user32.dll" ( _
    ByVal hWnd As Long, _
    ByVal hWndInsertAfter As Long, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal wFlags As Long) As Long

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

Private Declare Sub Sleep Lib "kernel32.dll" ( _
    ByVal dwMilliseconds As Long)

Private Declare Function GetWindowPlacement Lib "user32" ( _
    ByVal hWnd As Long, _
    ByRef lpwndpl As WINDOWPLACEMENT) As Long

Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type WINDOWPLACEMENT
    Length As Long
    flags As Long
    showCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type

Private Const MAX_PATH = 260&

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40

Private Const SW_MAX = 10&

Sub test()
    Dim path As String, i As Integer
    Dim leer As String, fs As FileSearch
    Dim myShell As Object, sFile As String
    Dim strPath As String, strShortPath As String, strFile As String
    Dim hWnd As Long, WinEst As WINDOWPLACEMENT
    Dim lngrow
    Set fs = Application.FileSearch
    With fs
        .LookIn = "D:\Eigene Dateien\test\" 'ANPASSEN !!!!!!!!!!!!!!!!!!!!!!!!
        .SearchSubFolders = True
        .Filename = "*.pdf"
        If .Execute > 0 Then
            For i = 1 To .FoundFiles.Count
                ShellExecute FindWindow("XLMAIN", vbNullString), "open", .FoundFiles(i), "", "", SW_MAX
            Next i
        Else
            MsgBox "There were no files found."
        End If
    End With
    Do
        Sleep 100
        hWnd = FindWindow("AdobeAcrobat", vbNullString)
        If hWnd <> 0 Then GetWindowPlacement hWnd, WinEst
        If WinEst.showCmd = 3 Then Exit Do
    Loop
    SetWindowPos FindWindow("XLMAIN", vbNullString), HWND_TOPMOST, _
        0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
    SetWindowPos FindWindow("XLMAIN", vbNullString), HWND_NOTOPMOST, _
        0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub

Gruß
Nepumuk
Excel & VBA – Beispiele
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige