Ich habe eine Frage bezüglich dem Ansprechen von Outlook-Fenstern mit VBA. Ich möchte Mails automatisch erstellen. Der User kann diese dann - wenn nötig - editieren und absenden. Da es mMn unschön ist, wenn man die einzelnen Fenster während der Prozedur aufpoppen sieht, minimiere ich diese sofort. Am Ende will ich alle Fenster wieder anzeigen. Allerdings schaffe ich nur, das letzte Fenster zu öffnen. (Gibt es einen Befehl, der die Fenster nicht maximiert sondern nur anzeigt?)
Hier man Code:
Sub Updates ()
Dim int_Count As Integer
Dim int_i As Integer
Dim obj_App As Object
Dim obj_Window As Object
On Error GoTo ErrorMsg
'Set variables
int_Count = ActiveWorkbook.Sheets("Tabelle1").Range("K11").Value 'Anzahl der zu sendenden _
_
Mails
'Create mails
For int_i = 1 To int_Count
str_User = "USERNAME"
str_Name = "NAME"
str_Mail = "MAILADRESSE"
str_text = "MAILTEXT"
Set obj_App = CreateObject("Outlook.Application")
With obj_App.CreateItem(0)
.GetInspector
.To = str_Mail
.CC = ""
.Subject = "BETREFF"
.htmlbody = str_text
.Attachments.Add ("ATTACHMENT")
.Display
End With
Set obj_Window = obj_App.ActiveWindow
If Not obj_Window Is Nothing Then
obj_Window.WindowState = olMinimized
End If
Set obj_App = Nothing
Set obj_Window = Nothing
Next int_i
Set obj_App = CreateObject("Outlook.Application")
Set obj_Window = obj_App.ActiveWindow
If Not obj_Window Is Nothing Then
obj_Window.WindowState = olMaximized
End If
Exit Sub
ErrorMsg:
Unload frm_Progress
If Not obj_file Is Nothing Then
Set obj_file = Nothing
End If
If Not obj_FSO Is Nothing Then
Set obj_FSO = Nothing
End If
If Not obj_App Is Nothing Then
Set obj_App = Nothing
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "An Error occured!" & vbNewLine & "Errornumber: " & Err.Number & vbNewLine & " _
Description: " & Err.Description, vbCritical + vbOKOnly, "Error"
End Sub