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

Mehrere Outlook Fenster in den Vordergrund

Mehrere Outlook Fenster in den Vordergrund
13.10.2017 08:25:37
ZD14
Guten Morgen ihr fleißigen Helfer ;)
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

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Mehrere Outlook Fenster in den Vordergrund
13.10.2017 09:18:27
Nepumuk
Hallo ZD14,
teste mal:
Option Explicit

Private Declare PtrSafe Function ShowWindow Lib "user32.dll" ( _
    ByVal hwnd As LongPtr, _
    ByVal nCmdShow As Long) As Long
Private Declare PtrSafe Function EnumWindows Lib "user32.dll" ( _
    ByVal lpEnumFunc As LongPtr, _
    ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Function GetClassNameA Lib "user32.dll" ( _
    ByVal hwnd As LongPtr, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) As Long
#If Win64 Then
Private Declare PtrSafe Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongPtrA" ( _
    ByVal hwnd As LongPtr, _
    ByVal nIndex As Long) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" ( _
    ByVal hwnd As LongPtr, _
    ByVal nIndex As Long) As LongPtr
#End If

Private Const GWL_STYLE As Long = -16&
Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_BORDER As Long = &H800000
Private Const MAX_CLASS_NAME As Long = 255
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const GC_CLASSNAME_MAIL As String = "rctrl_renwnd32"

Private llngRow As Long

Public Sub Start()
    Call EnumWindows(AddressOf WindowCallBack, ByVal 0)
End Sub

Private Function WindowCallBack(ByVal pvlngptrHwnd As LongPtr, ByVal lngptrParam As LongPtr) As Long
    Dim strClassName As String
    Dim lngReturn As Long
    Dim lngptrStyle As LongPtr
    lngptrStyle = GetWindowLong(pvlngptrHwnd, GWL_STYLE)
    If (lngptrStyle And (WS_VISIBLE Or WS_BORDER)) = (WS_VISIBLE Or WS_BORDER) Then
        strClassName = Space$(MAX_CLASS_NAME)
        lngReturn = GetClassNameA(pvlngptrHwnd, strClassName, MAX_CLASS_NAME)
        strClassName = Left$(strClassName, lngReturn)
        If strClassName = GC_CLASSNAME_MAIL Then Call ShowWindow(pvlngptrHwnd, SW_SHOWMAXIMIZED)
    End If
    WindowCallBack = 1
End Function

Gruß
Nepumuk
Anzeige
AW: Mehrere Outlook Fenster in den Vordergrund
13.10.2017 10:34:31
ZD14
Danke vielmals! So hab ich mir das vorgestellt. :)

302 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige