Help for a novice

S

SuperSlueth

I've read the help on reply event , but can't get it to work
I've tried placing this everywhere but I can't get it to run when the
user sends a reply.

I'm trying to find the right place to set the code so that only runs
when the user sends a reply

PLEASE can anyone help



Public WithEvents myItem As MailItem

Sub Initialize_Handler()
Set myItem = Application.ActiveInspector.CurrentItem
End Sub

Private Sub myItem_Reply(ByVal Response As Object, Cancel As Boolean)
MsgBox "Reply"
End Sub
 
S

Sue Mosher [MVP-Outlook]

We're confused, too. You've posted in a forum about Outlook custom forms, which use VBScript as their code language, but the topic of your post seems to deal with VBA/VB code. Please give us the "big picture" so we can understand what you're trying to do.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

I have users that get faxes as email attachments.
Sometimes as many as 6 or 7 per email, as GIF attachments.

Outlook 2003 doesn't allow you to open multiple attachments at 1 time.

I'm trying to write a VBA macro that opens all the attachments when
the user opens the email.

I don't want to open the attachments when the user uses Reply, Reply
All, or Forward. So I need to test for these and block those events

I only want to open the attachments when the user opens the eamil to
read.

All the code I've seen on the interent either opens attachments on new
mails as they come in or search the inbox for attachments and opens
them all

Maybe you have a simple solution to this seemingly easy task
 
S

Sue Mosher [MVP-Outlook]

Take a look at http://www.outlookcode.com/codedetail.aspx?id=1140. Check the message's Sent property equals False, then you know you have a reply, forward, or new message.

Note that this has nothing to do with custom forms.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

The code that you suggested, when does it run ....
I mean does the user have to do something or does this code run when a
new mail comes in.

The users here don't want the attachments for every mail to open. only
when the user opens it to read.

Quite often we get unwanted or duplicate mails with attachements ...
the user just wants to delete these without the attachments opening

Thanks for you continued help
I've included my code for your information



This is the code so far

Code in "ThisOutlookSession"


Dim WithEvents colInsp As Outlook.Inspectors
Public WithEvents myItem As Outlook.MailItem

Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)

Call Att_Open
End Sub


Code in Module ....
It runs fine when an email is opened to read, but also runs when the
user selects Reply. ReplyAll forward or New .... which i need to stop

Sub Att_Open()

Dim myolApp As Outlook.Application
Dim myinspector As Outlook.Inspector
Set myolApp = CreateObject("Outlook.Application")
Set myinspector = myolApp.ActiveInspector
Dim I As Integer


If TypeName(myinspector) = "Nothing" Then
Exit Sub

ElseIf Application.ActiveInspector.CurrentItem.Attachments.Count =
0 Then
MsgBox "No Attachments"

ElseIf Application.ActiveInspector.CurrentItem.Attachments.Count >
0 Then
I = Application.ActiveInspector.CurrentItem.Attachments.Count
MsgBox I

End If


End Sub
 
S

Sue Mosher [MVP-Outlook]

I don't see any code yet to instantiate colInsp. If you want the whole routine to run automatically, you need code in the Application_Startup event handler in ThisOutlookSession to handle that.

As I said in my earlier post, if you check the value of the message's Sent property and it equals False, then you know you have a reply, forward, or new message, one that you don't want to process.

Other issues:

Outlook VBA includes an intrinsic Application object, so you don't need to use CreateObject to create another one.

Also, you said "users." Outlook VBA code is not meant to be redistributed. Ultimately, you should be thinking about building this functionality into an OUtlook COM add-in. See http://www.outlookcode.com/d/comaddins.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

I have no experience in building COMs add-ins.
I'm not a programmer and had this landed on me.
 
S

Sue Mosher [MVP-Outlook]

Then I'd advise you to go back to the person who assigned the project and explain to them that you might need some outside help.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

Partly my own fault opening mi mouth and saying it shouldn't be that
difficult to do. .... learnt my lesson

anyway.

do you have some code that explains how to test for the sent property

I've tried

Set myItem = ActiveInspector
MsgBox myItem ..... returns the subject of the mail

If myItem.Sent = False Then

But i get an error " The obect doesn't support this method or
property"

can you help please
 
S

Sue Mosher [MVP-Outlook]

The problem with your code below is that ActiveInspector is not an item. It's just the window showing an item. In VBA, if you want the item, you use:

Set myItem = Application.ActiveInspector.CurrentItem

Because the Sent property is specific to the MailItem object, you should check that myItem is a MailItem before you do anything else. Then you can check the value of the Sent property:

If myItem.Class = olMail Then
If myItem.Sent = True Then
' it's not a newly created item
' put your code to work with myItem here
End If
End If

See http://www.outlookcode.com/d/propsyntax.htm for a basic primer on Outlook property syntax.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

I tried

f myItem.Class = olMail Then
If myItem.Sent = True Then

MsgBox "Test"

' it's not a newly created item
' put your code to work with myItem here
End If
End If


The msgbox pops up when a mail is opened for reading the first time,
also when the user selects reply, replyall or forward


I need something that ONLY works when the mail is opened for reading
.....not when a reply, reply all or forward is selected
 
S

Sue Mosher [MVP-Outlook]

How are you instantiating myItem?

I can't duplicate the results here on OUtlook 2003. THis is all my code:

Dim WithEvents colInsp As Inspectors

Private Sub Application_Startup()
Set colInsp = Application.Inspectors
End Sub

Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Set itm = Inspector.CurrentItem
If itm.Class = olMail Then
If itm.Sent = True Then
MsgBox "It's not a new item"
End If
End If
End Sub

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

OK, lets take a differnent approach

I've seen "Reply event"

Is there any way in VBA to see if theis event has happened.

What I read it as if the user selects reply, then i should be able to
test to see if this event is "True or False"


many thanks
 
S

Sue Mosher [MVP-Outlook]

Handling the Reply event is ***much*** more difficult because the message you can reply to changes every time you open an item or change your selection in the folder. THat requires a wrapper class; see http://www.outlookcode.com/d/vb.htm#wrapper

Did you try my code?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

Yes I tried your code, but it works on open mail (read), as well as
reply, replyall, & forward

If I use it as is, the attachments will open everytime the user
selects reply, replyall or forward ...... not very convenient

I'm looking for a way that it only works when the user opens a mail to
read... it shouldn't work anywhere else
 
S

Sue Mosher [MVP-Outlook]

It works fine here. Did you use exactly the code I posted? If not, show what you're using. Also, try stepping through it to see what's not working for you.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

In desperation I did a machine cleanup including the following
removed ALL vba code from outlook
ran Office repair
ran Scanpst ... errors found
deleted all caches and temps ... 134Mb removed
ran regcleaner..... 207 errors found and repaird or removed
reboot with scandisk
checked for and installed updates for windows & office .... 3 found
defragged hadrdisk
added your code to outlook

and it works now

not sure of the exact reason but at last got it to work

Thanks for all your help
 
S

SuperSlueth

I'm trying the following



Set myItem = Application.ActiveInspector.CurrentItem
Set myAttachments = myItem.Attachments
MsgBox myAttachments.Item(1).DisplayName

This displays the attachments files name ok

but when I try

myAttachments.Item(1).Open
I get an error

The attachmenats are GIF files and when I double click on an
attachment it opens with windows picture and fax viewer OK


Where am i going wrong with my code and is there a simple way in VBA
to open this type of attachment.
 
S

Sue Mosher [MVP-Outlook]

You can't open an attachment that way (and you'd know that if you looked in the object browser at the Attachment object; it has no Open method). You must save each attachment first to your hard drive and then open it, either with the appropriate automation for that type of file or with a Shell Execute type of command. See http://www.outlookcode.com/codedetail.aspx?id=1140 for a code sample.

You might also enjoy Eric's sample at http://msdn.microsoft.com/library/en-us/odc_ol2003_ta/html/Office_Outlook_ViewMultPictAttach.asp

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

SuperSlueth

Sorry I don't follow

If I double click on the attachment it opens without saving it to disk
therefore why can't it just be opend with code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top