thomas1972
Goto Top

Tabellenblatt per VBA als Email versende. Range Bereich angeben??

Hallo,

mit folgendem Code lasse ich das Tabellenblatt1 per Mail als CSV Datei versenden.

Wie bekomme ich es hin, dass nur ein gewisser Rangebereich versendet wird.

mit z.b. ThisWorkbook.Worksheets("Tabelle1").Cells(1).Resize(14).Value ect..
kommt er nicht klar.

z.b. Spalten A-N


Sub Mail_CSV()
Dim csvFullName$
Dim strMailEmpfaenger As String
Dim quelle As Range

'Delimiter angeben
Const sDelimiter$ = ";"

strMailEmpfaenger = "fewf@dede.de"

If Application.MailSystem <> xlNoMailSystem Then
Dim vValue As Variant
Do
vValue = InputBox("Für welche Nummersoll gemeldet werden?", "Nummer")
If IsNumeric(vValue) Then Exit Do
Loop

csvFullName = ThisWorkbook.Path
If Right$(csvFullName, 1) <> "\" Then csvFullName = csvFullName & "\"
csvFullName = csvFullName & "CROSS_Keyuser " & vValue & ".csv"

Application.ScreenUpdating = False

'CSV erstellen
'sDelimiter, Datei, Tabelle
Export_CSV sDelimiter, csvFullName, ThisWorkbook.Worksheets("Tabelle1")

Workbooks.Open Filename:=csvFullName


Application.ActiveWorkbook.SendMail strMailEmpfaenger, "CROSS Keyuser - Neuanlagen / Änderungen Cross Betriebsnummer: " & vValue, False
End If
ActiveWorkbook.Close False

If Dir(csvFullName, vbNormal) <> "" Then
Kill csvFullName
End If

Application.ScreenUpdating = True
End Sub

Sub Export_CSV(sDelimiter As String, strDatei As String, oTabelle As Worksheet)
Dim rngBereich As Range, strString$
Dim F As Integer
'löschen wenn vorhanden
If Dir(strDatei, vbNormal) <> "" Then
Kill strDatei
DoEvents
End If

Set rngBereich = oTabelle.UsedRange
F = FreeFile
Open strDatei For Append As #F
With Application
If rngBereich.Columns.Count > 1 Then
For Each rngBereich In rngBereich.Rows
strString = Join(.Transpose(.Transpose(rngBereich)), sDelimiter)
Print #F, strString
Next rngBereich
Else
For Each rngBereich In rngBereich.Rows
Print #F, rngBereich.Value
Next rngBereich
End If
End With
Close #F
End Sub

Content-Key: 292990

Url: https://administrator.de/contentid/292990

Printed on: April 19, 2024 at 17:04 o'clock

Mitglied: 114757
114757 Jan 13, 2016 at 14:53:22 (UTC)
Goto Top
Hier gibts die passende Funktion dafür:
Mittels VBA Makro Excel Zellen auslesen und diese in eine CSV Datei exportieren

Gruß jodel32