Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1528to1532
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

Formular per E-Mail versenden VBA (OS&Win)

Formular per E-Mail versenden VBA (OS&Win)
01.12.2016 15:47:46
Jamie
Liebe Community
ich komme gleich mit einem zweiten Thema.
Da ihr beim ersten Thema mir bereits super helfen konntet.
Ich benötige den Code, damit es mit MAC OS und Windows funktioniert.
Es soll das Tabellenblatt (blattgeschützt) per E-Mail im Anhang an einen Empfänger senden.
Hierbei erhalte ich bei "Set outObj = CreateObject ("Outlook.Application") ein Problem.
Liegt es am Mac OS? Wie kann ich den Code so darstellen das es für beide Versionen greift?
Freue mich auf Euer Feedback und bin sehr gespannt auf die Lösung.
Euer Jamie
Sub einzelnes_Blatt_senden()
ActiveSheet.Unprotect Password:="password"
Dim strBlatt As String
Dim strDatei As String
Dim strPfad As String
Dim outObj As Object
Dim Mail As Object
Dim strBodyText As String
Set outObj = CreateObject("Outlook.Application")
Set Mail = outObj.CreateItem(0)
strPfad = "C:\Temp"
strBlatt = ActiveSheet.Name
Sheets(strBlatt).Copy
ActiveWorkbook.SaveAs strPfad & "\" & ActiveSheet.Name
strDatei = ActiveWorkbook.FullName
With Mail
.To = "spoc@empf.ch"
'.CC = ""
.Subject = "Artikelstammdaten" 'Betreff
.BodyFormat = 2 '2 = HTML, 1 = Text
.Attachments.Add strDatei
.Body = strBodyText
End With
'** Erzeugte Datei schließen
Workbooks(Dir(strDatei)).Close
'** Erzeugte Datei wieder löschen
Kill (strDatei)
'** E-Mail anzeigen
Mail.Display
ActiveSheet.Protect Password:="password"
End Sub

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Dafür gibt es schon...
02.12.2016 10:37:05
Jamie
Hallo Case
vielen Dank, super Seite! Habe zwar bei Dr. Google nachgefragt, aber kam nicht auf eine solche Seite.
Ich habe jetzt mal folgende zwei Beispiele getestet und bei beiden bekomme ich eine Fehler-Meldung gemäss (Sub oder Function sind nicht definiert)
Ich habe den Code im Worksheet abgelegt sowie auch ein Modul erstellt, bei beidem bekomme ich es nicht hin.
Mach ich einen Denkfehler?
Sub Mail_workbook_Excel2011_1()
ActiveSheet.Unprotect Password:="password"
'For Excel 2011 for the Mac and Outlook 2011
'Note: The workbook must be Saved ones
Dim wb As Workbook
If Val(Application.Outlook) 


Sub Mail_Workbook_Excel2011_2()
'For Excel 2011 for the Mac and Outlook 2011
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
If Val(Application.Version) 

Anzeige
Dast steht doch...
02.12.2016 10:57:46
Case
Hallo, :-)
... alles klar im Text drin: ;-)
Note: To run the mail examples you must copy the macro of your choice and also two functions named MailFromMacWithOutlook and KillFileOnMac that you find on the bottom of this page. If you want to test more then one macro you only have to copy the two functions one time.
Servus
Case

AW: Dast steht doch...
02.12.2016 12:01:12
Jamie
Meinst du das?
Application.Version
hier habe ich mit .Version und Outlook versucht.
ging beides nicht.
oder stehe ich auf dem Schlauch?
Anzeige
Nein - Du musst die...
02.12.2016 13:02:12
Case
Hallo, :-)
... beiden Funktionen - "MailFromMacWithOutlook" und "KillFileOnMac" noch in das Modul kopieren! ;-)
Servus
Case

AW: Nein - Du musst die...
02.12.2016 15:28:17
Jamie
*klatschinsGesicht*
habe den Fehler gefunden, ich habe Mac Excel 2016 nicht 2011...
Hierbei musste ich diese Anleitung fahren:
http://www.rondebruin.nl/mac/macmail/macoutlook2016.htm
Jetzt hat mich aber das Ganze auf eine super Idee gebracht.
Wie kann ich bestimmte Zellen Inhalt vom Excel im Bodytext (E-Mail) Wiederspiegeln?
Mein jetziger Code ist:
Sub Mail_WorkSheet_or_Worksheets_in_Mac_Excel_2016_with_Outlook3()
'Only working in Excel 2016 for the Mac with Outlook 2016 as mail program
'Do not forget to add the 3 functions into your own workbook
'More Mail codes : http://www.rondebruin.nl/mac/ _
mail.htm
Dim Sourcewb As Workbook, DestWB  As Workbook, sh As Worksheet
Dim strbody As String, TempFileName As String
'Check if the AppleScriptTaskExcelScriptFile is in the correct location
If CheckAppleScriptTaskExcelScriptFile(ScriptFileName:="RDBMacOutlook.scpt") = False Then
MsgBox "Sorry the RDBMacOutlook.scpt file is not in the correct location, " & _
"Visit http://www.rondebruin. _
nl/mac/macmail/macoutlook2016.htm
for more information."
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Set reference to the source workbook
Set Sourcewb = ActiveWorkbook
'Create the body text in the strbody string
'The first and last line are used to set the font and font size
strbody = ""
strbody = strbody & "Hi there" & "
" & "
" & _ "This is line 1" & "
" & _ "This is line 2" & "
" & _ "This is line 3" & "
" & _ "This is line 4" strbody = strbody & "
" 'Copy the ActiveSheet to a new workbook, you can also use : Sourcewb.Sheets("MySheetName"). _ Copy 'Or for more sheets : Sourcewb.Sheets(Array("Sheet1", "Sheet3")).Copy ActiveSheet.Copy Set DestWB = ActiveWorkbook 'Delete the button on the one sheet workbook On Error Resume Next DestWB.Sheets(1).DrawingObjects.Visible = True DestWB.Sheets(1).DrawingObjects.Delete On Error GoTo 0 'Change all cells in the worksheets to values if you want 'I use .Value = .Value because PasteSpecial with CutCopyMode = False not work on a Mac 'For Each sh In DestWB.Worksheets 'With sh.UsedRange '.Value = .Value 'End With 'Next sh 'Enter the name of the file we just create TempFileName = "Part of " & Sourcewb.Name & " " _ & Format(Now, "dd-mmm-yy h-mm-ss") 'Call the MailWithMacOutlook2016 function to save the new file and create the mail 'When you use more mail addresses separate them with a , 'Look in Outlook>Preferences for the type and name of the account you want to use 'If accounttype is empty it will use the default mail account, accounttype can be pop or _ imap 'Note : It will use the signature of the account that you choose MailWithMacOutlook2016WorkSheet _ subject:="This is a test macro", _ mailbody:=strbody, _ toaddress:="ron@debruin.nl", _ ccaddress:="", _ bccaddress:="", _ displaymail:=True, _ accounttype:="", _ accountname:="", _ attachment:=TempFileName, _ FileFormat:=Sourcewb.FileFormat With Application .ScreenUpdating = True .EnableEvents = True End With End Sub

Anzeige

38 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige