Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1076to1080
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
Email per Code senden
27.05.2009 18:20:55
Volker
Schon wieder ein für mich wichtige Frage:
Wie kann ich bei einer Veränderung einer Bestimmten Zelle eine Sendung dieses Tabellenblatts als Anhang an eine bestimmte Emailadresse automatisch (möglichst ohne ein zutun vom Benutzer) auslösen?
Der Code sollte mit dem öffnen der Arbeitsmappe ausgelöst werden, und bei Veränderung der Zelle G 25 ausgelöst werden. Wenn nicht die Zelle G 25 verändert wurde, sondern irgend eine ander Zelle, soll nicht passieren.
Geht das?

10
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Email per Code senden
27.05.2009 19:26:27
ChrisL
Hallo Volker
Erstmal Code suchen:
http://www.office.gmxhome.de/_excel_outlook.htm
Diesen in ein Standardmodul d.h. Alt+F11, Menü "Einfügen", "Modul"
Dann fürs automatische Auslösen der Prozedur folgender Code verwenden:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("G25")) Then
Call DeinMakro
End If
End Sub


"DeinMakro" entspricht dem Namen vom Makro das du auslösen willst. Dieser Code nicht in ein Standardmodul sondern zur betreffenden Tabelle d.h. Alt+F11, links Doppelklick auf die Tabelle machen und anschliessend ins Codefenster reinkopieren.
Viel Spass beim Copy/Pasten ;)
cu
Chris

Anzeige
AW: Email per Code senden
27.05.2009 21:14:56
Volker
Hallo Chris,
ich habe den Code aus dem WWW in das Tabellenblatt kopiert, dann deinen Code ins Modul kopiert und die Zelle verändert.
Leider bekomme ich immer die Fehlermeldung Laufzeitfehler 13 und die Zeile gelb angezeigt.
If Not Intersect(Target, Range("G25")) Then
Kannst du mir da helfen?
AW: Email per Code senden
28.05.2009 07:58:15
ChrisL
vermutlich Standard und Klassenmodul verwechselt... Code aus WWW ins Standardmodul nicht zur Tabelle
cu
AW: Email per Code senden
28.05.2009 20:33:06
Volker
Hallo Chris,
leider geht es immer noch nicht. Ich bekomme die Fehlermeldung wieder.
Kannst du noch mal es bei dir versuchen?
Gruss Volker
AW: Email per Code senden
29.05.2009 08:48:44
ChrisL
Hallo Volker
Ist schwer zu erraten was falsch ist. Stell doch einfach mal eine Beispieldatei ins Netz, dann sollten wir den Fehler ruck-zuck haben.
cu
Chris
Anzeige
AW: Email per Code senden
27.05.2009 21:35:19
Volker
Hallo Sepp,
leider ist auch bei deinem Tipp für mich nicht alles klar.
1. Leider habe ich den Code nicht ganz so gut verstanden ( Ich weis zum Teil nicht was da abläuft).
2. Ich habe den Code im Anfang mit meiner Empfängeradresse versehen.
Bekomme eine Fehlmeldung. Die Nachricht konnte nicht an den SMTP gesendet werden. Der Transportfehlercode lautet xxxxxx. Der Serverantwort lautet not available.
Kannst du da helfen?
Anzeige
wer lesen kann...
27.05.2009 22:23:39
Josef
Hallo Volker,
... ist im Vorteil;-)
Du hast das nicht gelesen:

''Read this!!!
''
''This code will not work in Win 98 and ME.
''You must be connected to the internet when you run a example.
''
''It is possible that you get a Send error when you use one of the examples.
''AFAIK : This will happen if you haven't setup an account in Outlook Express or Windows Mail.
''In that case the system doesn't know the name of your SMTP server.
''If this happens you can use the commented green lines in each example.
''don 't forget to fill in the SMTP server name in each code sample where
''it says "Fill in your SMTP server here"
''
''When you also get the Authentication Required Error you can add this three lines.
''.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
''.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
''.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

sonst würdest du wissen, das du das hier

' iConf.Load -1 ' CDO Source Defaults
' Set Flds = iConf.Fields
' With Flds
' .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Fill in your SMTP server here"
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With

ausfüllen und die Auskommentierung entfernen sollst.
Gruß Sepp

Anzeige
AW: wer lesen kann...
28.05.2009 20:37:22
Volker
Lieber Sepp,
leider ist nicht jeder in der Lage, Englische Erklärungen zu l e s e n.
Mir ist das leider nicht gegeben!!
Kann man da trotzdem um Hilfe bitten
Gruss Volker
AW: wer lesen kann...
28.05.2009 20:51:55
Josef
Hallo Volker,
hier der Code mit ein paar deutschen Kommentaren.
Achte besinders auf die Zeile ####Hier####.
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

'Anpassen!
Private Const cstrRecipient As String = "a.b@c.com" 'Empfängeradresse
Private Const cstrSenderName As String = "Dein Name" 'Absendername
Private Const cstrSheetSend As String = "Tabelle1" 'Tabelle die Verschickt wird
Public Const cstrSheetWatch As String = "Tabelle1" 'Tabelle die Überwacht wird
Public Const cstrCellWatch As String = "G25" 'Überwachte Zelle
'###

Public varOldValue As Variant


''Read this!!!
''
''This code will not work in Win 98 and ME.
''You must be connected to the internet when you run a example.
''
''It is possible that you get a Send error when you use one of the examples.
''AFAIK : This will happen if you haven't setup an account in Outlook Express or Windows Mail.
''In that case the system doesn't know the name of your SMTP server.
''If this happens you can use the commented green lines in each example.
''don 't forget to fill in the SMTP server name in each code sample where
''it says "Fill in your SMTP server here"
''
''When you also get the Authentication Required Error you can add this three lines.
''.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
''.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
''.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
''
''don 't remove the TextBody line in the code. If you do you can't open the attachment (bug in CDO).
''If you don't want to have text in the body use this then .TextBody = ""


Sub sendSheet()
  'original by http://www.rondebruin.nl/
  
  Dim FileExtStr As String
  Dim FileFormatNum As Long
  Dim Sourcewb As Workbook
  Dim Destwb As Workbook
  Dim TempFilePath As String
  Dim TempFileName As String
  Dim iMsg As Object
  Dim iConf As Object
  Dim Flds As Variant
  
  With Application
    .ScreenUpdating = False
    .EnableEvents = False
  End With
  
  Set Sourcewb = ThisWorkbook
  
  'Copy the ActiveSheet to a new workbook
  Sourcewb.Sheets(cstrSheetSend).Copy
  
  'Or if you want to copy more then one sheet use:
  'Sourcewb.Sheets(Array("Sheet1", "Sheet3")).Copy
  
  Set Destwb = ActiveWorkbook
  
  'Determine the Excel version and file extension/format
  With Destwb
    If Val(Application.Version) < 12 Then
      'You use Excel 97-2003
      FileExtStr = ".xls": FileFormatNum = -4143
    Else
      'You use Excel 2007
      'We exit the sub when your answer is NO in the security dialog that you only
      'see when you copy a sheet from a xlsm file with macro's disabled.
      If Sourcewb.Name = .Name Then
        With Application
          .ScreenUpdating = True
          .EnableEvents = True
        End With
        MsgBox "Your answer is NO in the security dialog"
        Exit Sub
      Else
        Select Case Sourcewb.FileFormat
          Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
          Case 52:
            If .HasVBProject Then
              FileExtStr = ".xlsm": FileFormatNum = 52
            Else
              FileExtStr = ".xlsx": FileFormatNum = 51
            End If
          Case 56: FileExtStr = ".xls": FileFormatNum = 56
          Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
        End Select
      End If
    End If
  End With
  
  ' 'Change all cells in Destwb to values if you want
  ' For Each sh In Destwb.Worksheets
  ' sh.Select
  ' With sh.UsedRange
  ' .Cells.Copy
  ' .Cells.PasteSpecial xlPasteValues
  ' .Cells(1).Select
  ' End With
  ' Application.CutCopyMode = False
  ' Next sh
  ' Destwb.Worksheets(1).Select
  
  
  'Save the new workbook/Mail it/Delete it
  TempFilePath = Environ$("temp") & "\"
  TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
  
  With Destwb
    .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
    .Close savechanges:=False
  End With
  
  Set iMsg = CreateObject("CDO.Message")
  Set iConf = CreateObject("CDO.Configuration")
  
  '####Hier####
  iConf.Load -1 ' CDO Source Defaults
  Set Flds = iConf.Fields
  With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Deinen SMTP server hier eintragen" 'Findest du in den Kontoeinstellungen deines mailprogrammes!
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    ' 'Bei Authentifizierungsfehler sind auch folgende Zeilen notwendig!
    ' 'Username und Passwort deines E-Mail Accounts
    ' .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    ' .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username" 'Dein Username
    ' .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" 'Dein Passwort
    .Update
  End With
  '############
  
  With iMsg
    Set .Configuration = iConf
    .To = cstrRecipient
    .CC = ""
    .BCC = ""
    .From = cstrSenderName
    .Subject = "This is a test" 'Betreff
    .TextBody = "Hi there" 'Text - Achtung! nicht entfernen! "" eingeben wenn kein Text!
    .AddAttachment TempFilePath & TempFileName & FileExtStr
    .Send
  End With
  
  
  'Delete the file you have send
  Kill TempFilePath & TempFileName & FileExtStr
  
  With Application
    .ScreenUpdating = True
    .EnableEvents = True
  End With
End Sub

Gruß Sepp

Anzeige

299 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige