auto email 'From'-Feld und Anhaenge
abu
ich habe mir ein Code zusammen gebaut um per Knopf automatisch eine Mail mit Anhang zu oeffnen.
Nun stosse ich auf 2 Problem und hoffe ihr koennt mir helfen.
1. Ich muss die Mails von einer bestimmten Adresse aus verschicken und muss dazu immer die Adresse im 'From'-Feld eingeben. Da es immer die selbe ist wuerde ich es gerne autom. befuellen aber analog zu den anderen adressadressierungen geht das leider nicht: .From = Fehlermeldung
2. Momentan werden immer ein paar Daten in ein Template kopiert und dann die Mail generiert. Allerdings muss ich nun ne abfrage machen und gegebenenfalls mehrer Blaetter in der Arbeitsmappe speichern.
Die Abfrage bekomm ich ja hin aber wie sag ich Excel das er mehrer Arbeitsblaetter in eine Arbeitsmappe speichert?
Hier mal der Code den ich moment habe.
Gruss abu
Private Sub CommandButton2_Click()
Dim outObj As Object
Dim Mail As Object
Dim oilref As String
oilref = TextBox4.Value
If OptionButton1 = True Then
ActiveWorkbook.Worksheets("Stock check").Copy
Else
If OptionButton2 = True Then
ActiveWorkbook.Worksheets("Stock check RPS").Copy
Else
If OptionButton3 = True Then
ActiveWorkbook.Worksheets("Stock check").Copy
Else
MsgBox ("Please check Storer ID and try again")
Exit Sub
End If
End If
End If
With ActiveSheet
.Cells(4, 5) = Format(Now, "dd.mm.yy hh:mm")
.Cells(7, 3) = "OIL-" & oilref
.Cells(8, 3) = TextBox1.Value
.Cells(9, 3) = TextBox2.Value
.Cells(10, 3) = TextBox45.Value
.Cells(12, 3) = TextBox13.Value
.Cells(13, 3) = TextBox16.Value
If TextBox14 = "" Then
.Cells(12, 6) = TextBox13.Value
.Cells(13, 6) = TextBox17.Value
Else
.Cells(12, 6) = TextBox14.Value
.Cells(13, 6) = TextBox21.Value
End If
.Cells(18, 3) = TextBox22.Value
End With
TextBox101.Value = Format(Now, "dd.mm.yy hh:mm")
ActiveWorkbook.SaveAs "H:\Templates\Stock check request OIL-" & oilref & ".xls"
ActiveWorkbook.Close
Set outObj = CreateObject("Outlook.Application")
Set Mail = outObj.CreateItem(0)
With Mail
.Subject = "Stock check request for OIL-" & oilref
.Body = "Dear Team," & Chr(13) & Chr(13) & "please find attached a stock check request." & _
_
Chr(13) & Chr(13) & "If you have any questions please don't hesitate to contact us." & Chr(13) & _
"Please don't forget to reply or send your emails to: "
If OptionButton1 = True Then
.From = "" 'hier bekomm ich immer dioe Fehlermeldung
.To = "nlbt"
.CC = "nlbr"
Else
If OptionButton2 = True Then
.To = "trouble.rp"
.CC = "forps"
Else
If OptionButton3 = True Then
.To = "Jame"
End If
End If
End If
.Attachments.Add "H:\Templates\Stock check request OIL-" & oilref & ".xls"
End With
Mail.Display
Set Mail = Nothing
Set outObj = Nothing
Kill "H:\Templates\Stock check request OIL-" & oilref & ".xls"
End Sub