Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
640to644
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
640to644
640to644
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Pdf-File laden

Pdf-File laden
25.07.2005 10:37:22
Richard
Hallo,
hab eine Frage, ich starte mit folgendem Code mein PDF-File:

Sub Benutzerhandbuch()
On Error GoTo fehler
Shell _
("C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe R:\QV\Handbuch.pdf")
Exit Sub
fehler:
MsgBox "Pfadangabe ist nicht korrekt!"
End Sub

das Problem ist, dass die Anwendung nicht immer unter C sich befindet, jeder Rechner hat eine andere Adresse, ich muss bei jedem Rechner den Code anpassen, gibt es vilelleicht eine Möglichkeit dies zu umgehen, vielleicht so, dass er die Anwendung selber findet?
wäre dankbar für jede Antwort
gruß
richard

15
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Pdf-File laden
25.07.2005 10:53:52
Nepumuk
Hi,
klar, so:
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 GetActiveWindow Lib "user32.dll" () As Long

Private Const MAX_PATH = 260&

Private Const SW_MAXIMIZE = 3&

Private Sub prcOpen_PDF()
    Dim strPath As String, strShortPath As String, strFile As String
    strFile = "Handbuch.pdf"
    strPath = "R:\QV\"
    strShortPath = Space(MAX_PATH)
    GetShortPathName strPath & strFile, strShortPath, MAX_PATH
    ShellExecute GetActiveWindow, "open", strShortPath, "", strPath, SW_MAXIMIZE
End Sub

Gruß
Nepumuk
Excel & VBA – Beispiele
Anzeige
AW: Pdf-File laden
25.07.2005 10:59:53
MichaV
Hi,
so z.B.:
Option Explicit
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 Sub OeffneDatei()
ShellExecute 0, "Open", "R:\QV\Handbuch.pdf", vbNullString, vbNullString, 1
End Sub

Gruss- Micha
Opps @Euch beide
25.07.2005 11:12:46
MichaV
@ Richard: Nepumuks Code ist -insbesondere wenn API im Spiel ist - im Zweifelsfalle immer vorzuziehen
@ Nepumuk: hab nicht gesehen, daß Du schon was gepostet hast.
Gruss- Micha
Anzeige
null Problemo
25.07.2005 11:22:53
Nepumuk
Hi Micha,
in einem Diskusionsforum ist jeder Beitrag willkommen!!!
Gruß
Nepumuk
AW: null Problemo
25.07.2005 13:03:56
Richard
Hallo Nepumuk und Micha,
ich danke euch für die schnelle Antworten.
Ich hab jetzt beide ausprobiert und der Code von dir Nepumuk funktioniert irgendwie nicht, weiß jetzt nicht warum, vielleicht am Verweis? also es tut sich nichts, es kommt auch keine Fehlermeldung.
Ich hätte noch eine Frage, und zwar bin jetzt schon die ganze Zeit am rumwursteln, möchte ich per Inputbox Sheets einfügen, krieg das aber nicht so hin, das habe ich bis jetzt benutzt, i ist ja der Index, also ist es in dem Sinne falsch, wie könnte ich es noch machen? wär auch diesmal superdankbar für die Antwort

Sub Blatteinfügen()
Dim i As Integer
i = Application.InputBox _
("Geben Sie bitte die Anzahl der Blätter, die Sie einfügen wollen!")
ActiveWorkbook.Worksheets(i).Add
End Sub

gruß
richard
Anzeige
AW: null Problemo
25.07.2005 13:43:18
MichaV
Hi,
hast Du bei Nepumuks Variante den Pfad richtig eingegeben? Ohne \ am Ende! Ansonsten schreib mal
MsgBox ShellExecute(GetActiveWindow, "open", strShortPath, "", strPath, SW_MAXIMIZE) und teile die Zahl mit, die dann angezeigt wird.
Zu Deinem anderen Problem:

Dim i As Integer
For i = 1 To Application.InputBox _
("Geben Sie bitte die Anzahl der Blätter, die Sie einfügen wollen!")
ActiveWorkbook.Worksheets.Add
Next i

Gruss- Micha
AW: null Problemo
25.07.2005 13:59:13
Richard
Hallo Micha,
danke schön, hätte ich drauf kommen müssen,
bei dem Code von Nepumuk habe ich Backslash vergessen:-)
grüße
richard
Anzeige
AW: null Problemo
25.07.2005 14:00:42
Nepumuk
Hi,
der Backslash am Pfadende ist erforderlich. Mal sehen wie er auf eine bereinigte Pfadangabe reagiert:
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 GetActiveWindow Lib "user32.dll" () As Long

Private Const MAX_PATH = 260&

Private Const SW_MAXIMIZE = 3&

Public Sub prcOpen_PDF()
    Dim strPath As String, strShortPath As String, strFile As String
    strFile = "bpl08827.pdf"
    strFile = "Handbuch.pdf"
    strPath = "R:\QV\"
    GetShortPathName strPath & strFile, strShortPath, MAX_PATH
    strShortPath = Left$(strShortPath, InStr(1, strShortPath, vbNullChar) - 1)
    ShellExecute GetActiveWindow, "open", strShortPath, "", strPath, SW_MAXIMIZE
End Sub


Gruß
Nepumuk
Excel & VBA – Beispiele
Anzeige
AW: null Problemo
25.07.2005 14:16:28
MichaV
Hi Nepumuk,

strShortPath = String(255, 0))   '<--- fehlte, sonst gabs immer Fehler
GetShortPathName strPath & strFile, strShortPath, MAX_PATH

...aber wozu das Ganze?
Gruss- Micha
AW: null Problemo
25.07.2005 14:30:35
Richard
Hallo,
so hat es funktioniert, eine Frage noch, was ist eigentlich damit gemeint:
strFile = "bpl08827.pdf" ?
ich danke euch nochmal
gruß
richard
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 GetActiveWindow Lib "user32.dll" () As Long
Private Const MAX_PATH = 260&
Private Const SW_MAXIMIZE = 3&
Public 

Sub Benutzerhandbuch()
Dim strPath As String, strShortPath As String, strFile As String
strFile = "bpl08827.pdf"
strFile = "Handbuch.pdf"
strPath = "R:\QV"
strShortPath = String(255, 0)
GetShortPathName strPath & strFile, strShortPath, MAX_PATH
strShortPath = Left$(strShortPath, InStr(1, strShortPath, vbNullChar) - 1)
ShellExecute GetActiveWindow, "open", strShortPath, "", strPath, SW_MAXIMIZE
End Sub

Anzeige
AW: null Problemo
25.07.2005 14:58:15
MichaV
Hi Richard,
nun haste den Backslash wieder vergessen. Läuft der Code bei Dir wirklich so? Ich muß bei deser Variante strPath = "R:\QV\" schreiben.
Das strFile = "bpl08827.pdf" kannst Du löschen, hat keine Bedeutung.
Ganz schön verwirrend, das Ganze. Hast Du mal meinen kleine(re)n Code probiert?
Gruss- Micha
AW: null Problemo
25.07.2005 15:09:49
Richard
Hallo Micha,
stimmt, hab's wieder vergessen :-), ohne backslash läuft er nicht, ich schon komisch, wenn man das nicht weiß, kann man daran verzweifeln.
Dein Code habe ich auch ausprobiert, geht auch super, was ist eigentlich der Unterschied zw.den beiden?
gruß
richard
Anzeige
AW: null Problemo
25.07.2005 15:19:31
MichaV
Hi Richard,
Nepumuks Code ist das Hightech- Werkzeug, das alle Eventualitäten berücksichtigt und mit dem man ggf. auch Kuchen backen kann. (Fenstergrößen des zu öffnenden Programmes bestimmen, Arbeitsverzeichnis festlegen, Parameter übergeben, die ID des aufrufenden Programmes an das aufzurufende Programm übergeben usw. ...soweit ich das bisher überblicken kann)
Meine Variante ist da eher der Holzschraubenzieher. ;o)
Gruss- Micha
AW: null Problemo
25.07.2005 15:54:33
Nepumuk
Hi,
da ist beim herumkopieren was schief gelaufen und ich habs nicht gesehen. Also, das ganze nochmal:
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 GetActiveWindow Lib "user32.dll" () As Long

Private Const MAX_PATH = 260&

Private Const SW_MAXIMIZE = 3&

Public Sub prcOpen_PDF()
    Dim strPath As String, strShortPath As String, strFile As String
    strFile = "Handbuch.pdf"
    strPath = "R:\QV\"
    strShortPath = Space(MAX_PATH)
    GetShortPathName strPath & strFile, strShortPath, MAX_PATH
    strShortPath = Left$(strShortPath, InStr(1, strShortPath, vbNullChar) - 1)
    ShellExecute GetActiveWindow, "open", strShortPath, "", strPath, SW_MAXIMIZE
End Sub

ShellExecute ist sehr tolerant, aber wenn weiß, wie die einzelnen Parameter zu bedienen sind, sollte man es auch tun.
Gruß
Nepumuk
Anzeige
AW: null Problemo
25.07.2005 16:04:53
Richard
HAllo,
danke nochmal an euch beide, werd mal damit versuchen 'n Kirchstreusel zu backen;-)

gruß
richard

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige