?
Solved

how to get outlook attachment pathname

Posted on 2005-03-12
18
Medium Priority
?
1,180 Views
Last Modified: 2009-07-29
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
0
Comment
Question by:kinghaim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
18 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13531392
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13531428
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
 
LVL 1

Author Comment

by:kinghaim
ID: 13531526
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:kinghaim
ID: 13531545
i did not add any references that corisponed to the 2 functions.
the only reference i have is ADO.

 
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13531560
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13531598
I found this, not sure how much use this is to you :

http://www.danevans.co.uk/vba/
0
 
LVL 1

Author Comment

by:kinghaim
ID: 13531605
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
 
LVL 1

Author Comment

by:kinghaim
ID: 13531655
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13531677
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13531795
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
 
LVL 1

Author Comment

by:kinghaim
ID: 13531798
"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
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 500 total points
ID: 13531817
http://www.outlookcode.com/codedetail.aspx?id=294

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

Expert Comment

by:gecko_au2003
ID: 13531864
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
 
LVL 1

Author Comment

by:kinghaim
ID: 13531976
humm that's my problem oAttach.PathName is empty
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13532003
what about oAttach.FileName ?? OR

oAttach.PathName(oAttach.FileName)

or something like that to get the pathname of the currently selected file(s) ??
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13532013
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
 
LVL 1

Author Comment

by:kinghaim
ID: 13532253
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13532379
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Introduction to Processes
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question