PDA

View Full Version : Minimise When Attachment is opened



rsrc1147
11-29-2004, 05:00 AM
Hello.I have to say that this web site is ace. The thing is I have only ever used excel VBA and am totally lost on how to make an email with VBA attached. I have looked around the help files etc but can't really grasp the whole form and binding business. Basically, all I want is to send an email with an excel file attached and when the attachment is run, the email message and the outlook explorer are both minimised.

I have got this far:
If ReadAttachment.Type = 1 then
For x = 1 To Application.Explorers.Count
Application.Explorers.Item(x).WindowState = 2
Next
End If

but i don't know where to put this code or how to put it or how to minimise the message iteself aswell. I know this is a lot to ask but is there anyone who can walk me through the process in a real idiots guide please?

Thank you very much

James

Killian
11-29-2004, 10:38 AM
Hi James,

Well, if I understand correctly, you want to send an email from outlook that has vba attached that minimises the recipient's outlook app and mail item. Short answer: you can't.
What you can do is put some code in the WorkBook_Open event of your Excel attachment so that when it is opened, it refers to the Outlook app the recipient has open and minimises that. I'm not sure why because when the user opens the attachment it will be the active app - on top of everything else. Additionally, you will have some situations to deal with, such as: what if the recipient isn't using Outlook but some other email client? what if the recipient saves the attachment first then opens it some other time? or the attachment is saved to a shared location and opened by someone else?

Well maybe you don't care too much about that so here's your code, tweaked a little. You can paste the body of the code into WorkBook_Open and I think it should work

Enjoy
K :-)


Sub MinOL()

Dim x as Integer
'set a reference to outlook
Set olapp = CreateObject("Outlook.Application")
'loop though all the outlook explorer windows and minimize them
For x = 1 To olapp.Explorers.Count
olapp.Explorers.Item(x).WindowState = 1
Next
'loop though all the outlook item windows and minimize them
For x = 1 To olapp.Inspectors.Count
olapp.Inspectors.Item(x).WindowState = 1
Next
'release the reference
Set olapp = Nothing

End Sub

rsrc1147
11-29-2004, 11:07 AM
oh. ok well thank you anyway. yeah i'll use the excel version then. huh. fancy that. blimey. but thanks. just a little surprised. ok. cool.