der gefundene Code hat mir schon mal geholfen , allerdings nun mit Fehler :
1004- Anwendungs oder -objektdefenierter Fehler.
Ich habe vorher mit Excel2003 gearbeitet nun mit excel2010 (13)
Aufgabe soll eigentlich nur sein das er Tabellenblatt "Rechnung" im Verzeichnis C:\Archiv\rechnung
speichert. Der Speichername erstellt sich aus meheren Zellen, wobei H7 das Rechnungsdatum ist.
Frage1:Muss der Code ins Arbeitsblatt oder wie ich es gemacht habe in ein Modul?
Gruß Matthias G.
Option Explicit
Sub exportPrintarea()
Dim rng As Range
Dim objWB As Workbook
Dim strName As String, strPath As String
On Error GoTo ErrExit
GMS
strPath = "C:\Archiv\Rechnung" 'Speicherpfad - Anpassen!
If Right(strPath, 1) "\" Then strPath = strPath & "\"
With Sheets("Rechnung") 'zu exportierende Tabelle - Anpassen!
Set rng = .Range("$A$1:$H$35")
strName = .Range("A3&B3&H7").Text & ".xls" 'Zelle mit dem zu vergebenden Namen - Anpassen!
End With
Set objWB = Workbooks.Add
rng.Copy
With objWB.Sheets(1).Range("A1")
.PasteSpecial -4163
.PasteSpecial -4122
.PasteSpecial 8
End With
Application.CutCopyMode = False
objWB.SaveAs strPath & strName
objWB.Close
ErrExit:
If Err.Number 0 Then MsgBox Err.Number & vbLf & Err.Description, vbExclamation, "Fehler"
GMS True
Set rng = Nothing
Set objWB = Nothing
End Sub
Public Sub GMS(Optional ByVal Modus As Boolean = False)
Static lngCalc As Long
With Application
.ScreenUpdating = Modus
.EnableEvents = Modus
.DisplayAlerts = Modus
.EnableCancelKey = IIf(Modus, 1, 0)
If Not Modus Then lngCalc = .Calculation
If Modus And lngCalc = 0 Then lngCalc = -4105
.Calculation = IIf(Modus, lngCalc, -4135)
.Cursor = IIf(Modus, -4143, 2)
End With
End Sub