how to get outlook attachment pathname

hi everyone.

i have macro running on outlook checking what is the attachment pathname.

but path name is empty.
dose anyone know how to get the pathname.

here is the function


    For Each oAttach In objMailItme.Attachments
        sPath = oAttach.PathName 'here is my problem oAttach.PathName is empty
        If InStr(sPath, "\\MyServer\MyDataFolders\MyEmailAttachmentFolder") = 0 Then
            CheckAttachment = False
            MsgBox "Attachment is not from a valid Path"
            Exit Function
        End If
    Next
LVL 1
kinghaimAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shane Russell2nd Line Desktop SupportCommented:
What references or objects have you got because when I try that code it says runtime error 424 - object required. I have not done VBA for outlook before but If I know what reference(s) you have used then I am positive I can figure something out :) I am pretty sure it is a reference with regards to the objMailItme. Also when I inserted it into a macro it was

Sub Return_Path()


End Sub

hence the exit function did not work so does this mean you have this in your own function and call it from the macro ?
0
Shane Russell2nd Line Desktop SupportCommented:
http://vbcity.com/forums/topic.asp?tid=93733

http://www.fontstuff.com/outlook/oltut01.htm

Those are 2 I found. Maybe they can help you out :) A little busy now so I will try and find some more in a while :)

Other then that I just need to know the references or objects or whatever you have used so that I can mess around with this code :)
0
kinghaimAuthor Commented:
Thank you for the response gecko_au2003

to clarify my problem, i am posting the 2 functions in the macro that need to be fixed.


Public UserAccount As String

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
   
    On Local Error GoTo ErrItemSend
   
    frmLogIn.Show 1 ' Force the user to Log In to the Server before sending the Email
   
    'check the user account
    If UserAccount = "" Or UserAccount = "Error" Then
        MsgBox "Unable to log you in, please try again later. " & vbLf & _
        "if the problem persist please contact your system administrator"
        Cancel = True
        Exit Sub
    End If
   
    If CheckAttachment(Item) Then
        Cancel = False
    Else
        Cancel = True
    End If
   

ErrItemSend:
    If Err.Number <> 0 Then
        MsgBox Err.Description
        Cancel = True
    End If
End Sub

Private Function CheckAttachment(ByVal objMailItme As MailItem) As Boolean
    On Local Error GoTo ErrCheckAttachment
    Dim oAttach  As Attachment
   
    For Each oAttach In objMailItme.Attachments
        sPath = oAttach.PathName 'here is my problem oAttach.PathName is empty
        If InStr(sPath, "\\MyServer\MyDataFolders\MyEmailAttachmentFolder") = 0 Then
            CheckAttachment = False
            MsgBox "Attachment is not from a valid Path"
            Exit Function
        End If
    Next
   
    CheckAttachment = True
   
ErrCheckAttachment:
    If Err.Number <> 0 Then
        CheckAttachment = False
        MsgBox Err.Description
    End If
End Function

i have backup function that basically check the "valid directory" for the file and  replace the attachment with the one in that directory (just so the user will not cheat the macro). but i do not want to use that because of permission/Security issues.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

kinghaimAuthor Commented:
i did not add any references that corisponed to the 2 functions.
the only reference i have is ADO.

 
0
Shane Russell2nd Line Desktop SupportCommented:
From the macro I call this :

Call Application_ItemSend(Item, False)

Not sure what Item is as you have that byval, so does this mean you have the path to the file you want to attach in there so it would be :

Call Application_ItemSend("C:\excelfile.xls",false)

if not then I need an example of how to call the function so that I can get it to work, I have also tried just calling the CheckAttachment function to no success, when I just had the code from your question it gave me an error on this line :

For Each oAttach In objMailItme.Attachments

which I am sure is fixed now because it is inside of the correct function as you posted :)
0
Shane Russell2nd Line Desktop SupportCommented:
I found this, not sure how much use this is to you :

http://www.danevans.co.uk/vba/
0
kinghaimAuthor Commented:
the Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
is outlook Sub that get called every time you click the send button.
where Item is MailItem(the email) and Cancel is where you set the Email to be sent or not, by default Cancel = True (would be Sent)  
0
kinghaimAuthor Commented:
thanks for the link.
 but that is not what i need that macro check the Email body for "Attach" String and then check to see if you have attachment, if not it will pop up a message saying that in the email body you mention attachment but you have no attachment then you will have the option to send the mail or cancel the send.

It uses the same application sub “Application_ItemSend” but it dose not have what I need
0
Shane Russell2nd Line Desktop SupportCommented:
click on that one line you are having problems with in order to debug it :

sPath = oAttach.PathName 'here is my problem oAttach.PathName is empty

Attach a file and then run your coding, after you attach something is the path still empty ? You could also try and programitcally attach something before you check its path. Is that the correct code to get the path though ?

Just you said it does not return a path but you did not mention nothing about attaching anything first so just stating the obvious to make sure.



0
Shane Russell2nd Line Desktop SupportCommented:
http://www.vbaexpress.com/forum/showthread.php?p=6329#post6329

http://www.vbaexpress.com/forum/showthread.php?p=16652#post16652

Those are 2 others I have found, closest thing I can find to help you out. basically go to www.vbaexpress.com and do a search on there to see if they have any solutions to your problem. Other then that I am jumping around in the dark as I do not really use VBA / macros to automate things. Something I will need to learn but later on :-S

Sorry I can not help you much more :-S
0
kinghaimAuthor Commented:
"click on that one line you are having problems with in order to debug it" Done that that's how i know the path is empty
"Attach a file and then run your coding, after you attach something is the path still empty ?" yes
"You could also try and programitcally attach something before you check its path." well if i attach something like that i would know the path simply because i attached it.
 Is that the correct code to get the path though ? i don't know, and that what i would like to know.

0
Shane Russell2nd Line Desktop SupportCommented:
http://www.outlookcode.com/codedetail.aspx?id=294

Try that, I will research that attach command to see if it exists
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shane Russell2nd Line Desktop SupportCommented:
You could try and do something simple like make a macro that just displays the attachment path something like so :

Dim oAttach  As Attachment
MsgBox oAttach.PathName

I checked that command and it is in the drop down list. When you type oAttach and type a . <DOT> it drops down a list and that command exists.

If that piece of code displays the path in your new macro then obviously it works, if it does something else then obviously it is not what you want.
0
kinghaimAuthor Commented:
humm that's my problem oAttach.PathName is empty
0
Shane Russell2nd Line Desktop SupportCommented:
what about oAttach.FileName ?? OR

oAttach.PathName(oAttach.FileName)

or something like that to get the pathname of the currently selected file(s) ??
0
Shane Russell2nd Line Desktop SupportCommented:
Sorry about all the posts and suggestions, just never done something like this before so I am just trying to figure this out by trying different things.
0
kinghaimAuthor Commented:
well we've got it gecko_au2003

one of your link gave me idea to use FileDialog to attach the files, and it's working, not like i would like it to but I’ll take it.

Thanks for the hard work.

the poins are yours.
0
Shane Russell2nd Line Desktop SupportCommented:
thanks kinghaim, sorry I couldnt be of more help. I have never done this sort of thing before. If you would like I can carry on researching and see if we can come up with another solution. Not sure how succesful that will be though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.