Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
712to716
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
712to716
712to716
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

PDF-Formel

PDF-Formel
03.01.2006 11:25:42
BEATE
Hallo Leute!
Hab folgendes Problem.
Hab mal von Nepumuk dankenswerter weise, diesen super Code bekommmen, mit dem man ein pdf drucken kann und der gewünschte Ordner und Dateiname aus den Zellen entnommen wird. Funktioniert auch super.
Leider ist aber das Problem, dass, obwohl das für Adobe untypisch ist, die gesamte Arbeitsmappe ausgedruckt. Ich möchte aber gezielt nur das Tablellenblatt ausdrucken in dem ich mich befinde.
Weiss jemand einen Rat?
Bin dankbar für jeden Hinweis
Grüße
BEATE
**********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
'Liest alle unter dem aktuell angemeldeten Benutzer
'installierten Drucker aus
'by Nepumuk
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" ( _
ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize 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 GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As Long
Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
Private Const MAX_PATH = 260&
Private Const SW_MAXIMIZE = 3&
Private Const MAX_PRINTERS = 16
Private strPrinterNames(MAX_PRINTERS) As String
Private strPrinterDrivers(MAX_PRINTERS) As String
Private strPrinterPorts(MAX_PRINTERS) As String
Private intPrinterCount As Integer
Sub Start_Print()
'by Ramses
'Druckt die übergebene Tabelle als PDF-Datei
'in das aktuelle Verzeichnis wo die Mappe gespeichert ist
Call Print_to_PDF(ActiveSheet)
End Sub
Public Sub Print_to_PDF(tarWks As Worksheet)
'by Ramses
'*********************************
'Verweise setzen auf
'Microsoft Office 10.0 / 11.0 Object Library und
'Acrobat Distiller
'*********************************
'Zusätzlich wird das Klassenmodul classAcroDist benötigt
Dim myAdobeDist As classAcroDist 'see class module
Dim myWB As Workbook
Dim strFilename As String
Dim strFileToPrintPath As String
Dim DistInputPS As String
Dim DistOutputPDF As String
Dim DistJobOptions As String
Dim oldActivePrinter As String
Set myAdobeDist = New classAcroDist
'Distiller ausgeblendet startetn
myAdobeDist.myAdobeDist.bShowWindow = False
'Alle aktuellen Printjobs des Distillers stoppen
myAdobeDist.myAdobeDist.bSpoolJobs = False
'Alten Drucker aufnehmen
oldActivePrinter = Application.ActivePrinter
'Workbook zuweisen
Set myWB = Workbooks(tarWks.Parent.Name)
'Pfad der Mappe extrahieren
strFileToPrintPath = Worksheets("Planungskizze").Cells(2, 2).Text & "\"
'Dann wechsle vorher in den Pfad der Datei
ChDrive (Left(strFileToPrintPath, 2))
ChDir strFileToPrintPath
'Zur druckender: Mappenname_Tabelle1
strFilename = Worksheets("Planungskizze").Cells(2, 1).Text
'EXCEL kann nur PS-Files direkt drucken
'daher muss sowohl PS-File wie auch PDF-File definiert werden
DistInputPS = strFileToPrintPath & strFilename & ".ps"
DistOutputPDF = strFileToPrintPath & strFilename & ".pdf"
'Der Druckername wird automatisch ermittelt
'in der Funktion "Get_Adobe_Printer"
myWB.PrintOut ActivePrinter:=Get_Adobe_Printer, prtoFilename:=DistInputPS, PrintToFile:=True
'Dem Distiller das PS-File zum konvertieren übergeben
Call myAdobeDist.myAdobeDist.FileToPDF(DistInputPS, DistOutputPDF, DistJobOptions)
'Schauen wie lange er braucht
'und STatus OK meldet
Do While Not myAdobeDist.blnFinished
DoEvents
Loop
If myAdobeDist.blnFinished Then
MsgBox "DAS PDF WURDE FÜR DIE KRICKON GMBH ERFOLGREICH ERSTELLT"
Else
MsgBox "Fehler beim Druck in PDF Datei aufgetreten"
End If
Call Open_PDF(strFileToPrintPath, strFilename & ".pdf")
'Alten Drucker wieder herstellen
Application.ActivePrinter = oldActivePrinter
'Variablen leeren
Set myAdobeDist = Nothing
End Sub
Function Get_Adobe_Printer() As String
'Adobe Drucker bestimmen
Dim strBuffer As String
Dim intIndex As Integer
strBuffer = Space$(8192)
GetProfileString "PrinterPorts", vbNullString, "", strBuffer, Len(strBuffer)
prcGetPrinterNames strBuffer
prcGetPrinterPorts
For intIndex = 0 To intPrinterCount
If InStr(1, strPrinterNames(intIndex), "Adobe") > 0 Then
'Genaue Druckerbezeicnung übergeben
Get_Adobe_Printer = strPrinterNames(intIndex) & " auf " & strPrinterPorts(intIndex)
Exit For
End If
Next
End Function

Private Sub prcGetPrinterNames(ByVal strBuffer As String)
Dim intIndex As Integer
Dim strName As String
intPrinterCount = 0
Do
intIndex = InStr(strBuffer, Chr(0))
If intIndex > 0 Then
strName = Left$(strBuffer, intIndex - 1)
If Len(Trim$(strName)) > 0 Then
strPrinterNames(intPrinterCount) = Trim$(strName)
intPrinterCount = intPrinterCount + 1
End If
strBuffer = Mid$(strBuffer, intIndex + 1)
Else
If Len(Trim$(strBuffer)) > 0 Then
strPrinterNames(intPrinterCount) = Trim$(strBuffer)
intPrinterCount = intPrinterCount + 1
End If
strBuffer = ""
End If
Loop While (intIndex > 0) And (intPrinterCount < MAX_PRINTERS)
End Sub


Private Sub prcGetPrinterPorts()
Dim strBuffer As String
Dim intIndex As Integer
For intIndex = 0 To intPrinterCount - 1
strBuffer = Space$(1024)
Debug.Print GetProfileString("PrinterPorts", strPrinterNames(intIndex), "", strBuffer, Len(strBuffer))
GetProfileString "PrinterPorts", strPrinterNames(intIndex), "", strBuffer, Len(strBuffer)
prcGetDriverAndPort strBuffer, strPrinterPorts(intIndex)
Next
End Sub


Private Sub prcGetDriverAndPort(ByVal Buffer As String, PrinterPort As String)
Dim intDriver As Integer
Dim intPort As Integer
PrinterPort = ""
intDriver = InStr(Buffer, ",")
If intDriver > 0 Then
intPort = InStr(intDriver + 1, Buffer, ",")
If intPort > 0 Then
PrinterPort = Mid$(Buffer, intDriver + 1, intPort - intDriver - 1)
Debug.Print PrinterPort
End If
End If
End Sub

Sub Open_PDF(strPath As String, strFile As String)
'by Nepumuk
Dim strShortPath As String
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

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub

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

Betreff
Datum
Anwender
Anzeige
@ Nepumuk - PDF-Formel
03.01.2006 12:35:47
BEATE
Hallo Nepumuk!
Vielleicht kannst DU mir kurz helfen, da der Code von Dir ist.
Vielen Dank
Grüße Beate
AW: @ Nepumuk - PDF-Formel
03.01.2006 22:24:31
DieterB
Hallo Beate,
hast du es mal mit
With ActiveSheet versucht?
Gruß DieterB
AW: @ Nepumuk - PDF-Formel
03.01.2006 22:52:11
BEATE
Hallo Dieter!
Vielen Dank für Deinen Hinweis-hast du eine Idee wo und wie ich das einbauen könnte?
Grüße
BEATE
AW: @ Nepumuk - PDF-Formel
03.01.2006 22:56:45
DieterB
Ja,
with ActiveSheet
Druckmakro
end with
Dann wird definitiv nur das aktive Blatt ausgedruckt.
Hatte den Code aus dem anderen Thread übernommen, aber bei mir
unetr E2000 läuft das Teil nicht
Gruß DieterB

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige