Liebes Forum, ich habe auf einem Button die nachfolgende Sub mit dem ich per Buttonklick eine zuvor abgespeichertes Mail (*.msg) wieder ansehen möchte. Der Code funktioniert, Outlook wird zwar gestartet jedoch minimiert. Wie bringt man Outlook dazu im Maximize oder Normal Mode zu starten. Vielen Dank für jegliche Vorschläge, ev. hat auch jemand ein anderen Ansatz wie man das lösen kann.
Sub OpenMsgFileAndActivateOutlook()
Dim olApp As Object
Dim olNameSpace As Object
Dim olMailItem As Object
Dim msgFilePath As String
' Set the path to your .msg file
msgFilePath = Forms!Auftrag_det_f!file2send
' Check if Outlook is already running
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
' Outlook is not running, so start it
Set olApp = CreateObject("Outlook.Application")
End If
' Check if the .msg file exists
If Not Dir(msgFilePath) = "" Then
Set olNameSpace = olApp.GetNamespace("MAPI")
' Open the .msg file
Set olMailItem = olApp.CreateItemFromTemplate(msgFilePath)
' Display the .msg file
olMailItem.Display
' Activate Outlook
olApp.ActiveWindow.Activate
' Clean up objects
Set olMailItem = Nothing
Set olNameSpace = Nothing
Else
MsgBox "The specified .msg file does not exist.", vbExclamation
End If
' Clean up Outlook object if it was created
If Not olApp Is Nothing Then
Set olApp = Nothing
End If
End Sub
Zitat von: vittorio1950 am September 02, 2023, 23:46:55' Activate Outlook
olApp.ActiveWindow.Activate
Füge doch hier im Anschluss mal ein:
olApp.ActiveWindow.WindowState = olMaximizedAnsonsten hatte ich kürzlich ausführlicher zu dem Thema geschrieben: Outlook Automation – Showing the Outlook Main Window (https://codekabinett.com/rdumps.php?Lang=2&targetDoc=outlook-automation-main-window)