Hallo zusammen,
ich möchte einige Spalten, zB A, B, E, F, H, M aus einem Dokument als PDF exportieren, dabei alle Zeilen bis zum Ende. Ausgelassene Spalten sollen aber weggelassen werden.
Der Range Select funktioniert nicht richtig, ich bekomme die ausgewählen Spalten jeweils separat auf einem Blatt angezeigt und nicht nebeneinander. Hat jemand eine Idee?
Hier ist das was ich mir bisher zusammen gebaut habe:
Sub Export_and_Print_1()
'setting up the paper
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.Zoom = False
.FitToPagesWide = 1
End With
Application.PrintCommunication = True
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strSelection As Range
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "yyyymmdd\_hhmm")
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")
'create default name for saving file
strFile = strName & "_" & strTime & ".pdf"
strPathFile = strPath & strFile
'select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Bitte wählen Sie den Speicherort.")
'export to PDF if a folder was selected before
If myFile <> "False" Then
wsA.Select
'hier in der folgenden Zeile passt irgendetwas nicht
Set strSelection = wsA.Range("A:A,B:B")
strSelection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
'confirmation message with file info
MsgBox "PDF wurde erfolgreich erstellt: " _
& vbCrLf _
& myFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "PDF konnte nicht erstellt werden!"
Resume exitHandler
End Sub
|