AW: Drucken
03.10.2010 10:17:23
Tino
Hallo,
ok. versuch mal diesen Code
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
'*************************************************************
Sub Print_Files()
Dim rngBereich As Range, rngRange As Range
Dim strFile$, strFehlerDatei$, lngRow As Long
'Pfad anpassen
Const sPath$ = "C:\Benutzer\Manfred\Haus\Zum Druck\"
'Bereich Festlegen
With Tabelle1
Set rngBereich = .Range("I5:K21")
End With
On Error GoTo ErrorH:
ChDrive Left$(sPath, 2)
ChDir sPath
lngRow = rngBereich(1).Row - 1
For Each rngRange In rngBereich.Columns(1).Cells
If rngRange <> "" Then
strFile = sPath$ & rngBereich.Cells(rngRange.Row - lngRow, 2)
strFile = strFile & "\" & rngBereich.Cells(rngRange.Row - lngRow, 3) & ".doc"
If Dir(strFile, vbNormal) <> "" Then
Call ShellExecute(0, "print", strFile, "", "", 6)
Else
strFehlerDatei = strFehlerDatei & strFile & vbCr
End If
End If
Next rngRange
If strFehlerDatei <> "" Then
MsgBox "Datei(en) nicht gefunden" & vbCr & vbCr & strFehlerDatei, vbExclamation, "Fehler"
End If
Exit Sub
ErrorH:
MsgBox Err.Description, vbCritical + vbMsgBoxSetForeground + vbMsgBoxHelpButton, _
"Error: " & Err.Number, Err.HelpFile, Err.HelpContext
End Sub
Gruß Tino