PDA

View Full Version : switch between active windows



aeromedic101
01-07-2008, 06:01 PM
I would like some advice as to how to identify different open emails. I need to develop a script that can close a specific email (and save to drafts) not necessarily the "active window."

Thanks all

Oorang
01-11-2008, 07:13 PM
Hi Aero,
Welcome to the board. I think we can help you with that, but I need to ask you some questions. How did the emails get opened, by user or code? (If code, please post code.) What is going to trigger the running of the script you have in mind, the user or an event (if event, which one?)

aeromedic101
01-12-2008, 09:07 AM
Thank you very much! :hi:

The user opens the email and highlights a relevant section of text. A macro button is selected and the script takes over.

It creates a new email containing the relevant text in the body (with appropriately added comments):
Dim OL As Object
Dim EmailItem As Object
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
etc etc.

the original email is now open as well as the new email (which is the active window.) Since posting my request, this is the script i have come up with to close the original email: (the script is active in the original email)

OriginalEmail = ActiveWindow.Caption

Call CreateEmail ' Creates the new email with content
OpenEmail = Windows.Count ' Count the number of open emails
For i = 1 To (OpenEmail - 1)
ActiveWindow.Next.Activate ' cycle through open emails
CurrentEmail = ActiveWindow.Caption ' get the email name
If CurrentEmail = OriginalEmail Then 'there is a match
ActiveWindow.Close (True) ' close
GoTo TheEnd ' exit cycle
End If
Next i

I dont know if this is an acceptable way to do things but it works, although there are things that cause errors.

The added caveat is that i now need to know how to set a reminder on the original email that has been closed. Ie after 5 min activate the alert reminder. The idea is that if a response to the created email has not been received, the original email can be forwarded. i tend to forget it is there if i do not get a reminder... and we have a lot of these emails a day

Thanks