Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1832to1836
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
Inhaltsverzeichnis

VBA Versenden Teil einer Tabelle

VBA Versenden Teil einer Tabelle
18.06.2021 20:16:14
Patrik
Viele Grüsse an das Forum
Ich versuche seit längerer Zeit eine VBA Programmierung so umzugestalten, das aus einer Arbeitsmappe - nicht unsprünglich die komplette Seite (DATA) versendet wird, sondern nur ein gewisser Abschnitt.
Irgendwie geling mir das auch, nur habe ich dann Kopiien die ich möchte, und der markierte Abschnitt (Range A1:BE20) verliert irgenwie die "Form" - Die Spalten und Zellen sing grösser.
Bin beim Suchen in den Unterschiedlichsten Foren leider nicht fündig geworden.
Bitte hiermit um ein wenig Hilfe.
Vielen Dank.
Ursprüngliche VBA :

Sub speichern und aktuelle Seite versenden()
'Update 20131209
Dim xFile As String
Dim xFormat As Long
Dim Wb As Workbook
Dim Wb2 As Workbook
Dim FilePath As String
Dim FileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
On Error Resume Next
Application.ScreenUpdating = False
Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
FileName = Wb.Name
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
With OutlookMail
.To = "XXX@XXX.com"
.CC = ""
.BCC = ""
.Subject = "REPORT, Stand vom " & Date
.Body = "Automatisch versendeter Report"
.Attachments.Add Wb2.FullName
.Display
End With
Wb2.Close
Kill FilePath & FileName & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True
End Sub
und hier mein Versuch der "so irgendwie halbwegs" funktioniert :

Sub SendRange()
On Error Resume Next
Application.ScreenUpdating = False
Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
'Update 20131209
Dim xFile As String
Dim xFormat As Long
Dim Wb As Workbook
Dim Wb2 As Workbook
Dim Ws As Worksheet
Dim FilePath As String
Dim FileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim WorkRng As Range
Set WorkRng = Range("A1:BE20")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Wb = Application.ActiveWorkbook
Wb.Worksheets.Add
Set Ws = Application.ActiveSheet
WorkRng.Copy Ws.Cells(1, 1)
Ws.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabl
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
FileName = Wb.Name
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
With OutlookMail
.To = "bbb@bbb.com"
.CC = ""
.BCC = ""
.Subject = "REPORT, Stand zum " & Date
.Body = "Automatischer Report"
.Attachments.Add Wb2.FullName
.Display
End With
Wb2.Close
Kill FilePath & FileName & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True
End Sub

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: VBA Versenden Teil einer Tabelle
19.06.2021 11:54:41
volti
Hallo Patrik,
vielleicht hilft Dir diese Idee weiter.
PS: Gehe davon aus, dass immer nur eine XLSX-Datei ohne Makros versendet werden soll....
Code:

[Cc][+][-]

Sub MailSendenMitSignatur() Dim sFilename As String, Wb As Workbook Set Wb = ActiveWorkbook ' XLSX-Datei erzeugen sFilename = Environ$("TEMP") & "&bsol;" & Left$(Wb.Name, InStrRev(Wb.Name, ".") - 1) & ".xlsx" Workbooks.Add ActiveSheet.Name = "Data" Wb.Sheets("Data").Range("A1:BE20").Copy Range("A1").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False ActiveSheet.Paste Range("A1").Select ActiveWorkbook.SaveAs Filename:=sFilename, _ FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False ActiveWorkbook.Close ' Mail kreieren With CreateObject("Outlook.Application").CreateItem(0) .GetInspector ' sorgt für die Signatur .To = "XXX@XXX.com" .CC = "" .BCC = "" .Subject = "REPORT, Stand vom " & Date .Body = "Automatisch versendeter Report" _ & vbCr & vbCr & .Body ' Mailtext mit Signatur If Dir$(sFilename) <> "" Then ' Anlage dran .Attachments.Add sFilename Kill sFilename End If .Display End With End Sub

_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz

Anzeige

300 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige