简体   繁体   中英

Bring newly created Outlook appointment window in front

Is there any way to bring newly created Outlook appointment window in front to use Sendkeys functions? I am creating new appointment from Excel, copying data from workbook to body and modifying appointment to Skype meeting by sending keys. However sometimes appointment opens behind Excel and SendKeys operation does not work.

I have tried to use AppActivate but I guess I am doing in the wrong way as debugger says Invalid procedure call or argument . Also alternatives are welcomed.

I have also tried, but it did not work all the time and sometimes appointment window opened in background anyway:

Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
.....

Dim olAppt As Outlook.AppointmentItem
Dim HWNDSrc As Long
.....
Set olAppt = olApp.CreateItem(olAppointmentItem)

    SetForegroundWindow HWNDSrc
.....

Here is my full code:

Sub CreateNewOutlookAppointment()

Dim olApp As Outlook.Application
Dim olAppt As Outlook.AppointmentItem

Set olAppt = Nothing
Set olApp = Outlook.Application
Set olAppt = olApp.CreateItem(olAppointmentItem)

AppActivate olApp

    With olAppt
        .Subject = "Bid review" & ", " & ThisWorkbook.Sheets("Other Data").Range("P23").Value
        ThisWorkbook.Sheets("Templates").Range("M202:M223").Copy
        .Display
        .GetInspector.WordEditor.Windows(1).Selection.PasteAndFormat wdPASTERTF
    End With
        Application.SendKeys ("%HOM")
Set olAppt = Nothing

End Sub

尝试调用Inspector.Activate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM