Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Send/Store (Outlook XP)

    I have some sample code (below) that present the Folder Picker as an Outlook email is sent. The user may pick which folder the outgoing message is to be stored in. The macro, because of its name, overtake the Send command. I would like to use this same macro, but have it run from a separate button on the toolbar, Send & File. But if I change the name of this macro, Outlook doesn't even recognize that it's in the VBA Project.

    Is this an Outlook security safeguard that I can't get around, or do I just need to know a trick to have this function on any outgoing mail item?

    Thanks,
    Richard Barrett

    Private Sub Application_ItemSend(ByVal Item As Object, _
    Cancel As Boolean)
    Dim objNS As NameSpace
    Dim objFolder As MAPIFolder
    Set objNS = Application.GetNamespace("MAPI")
    Set objFolder = objNS.PickFolder
    If TypeName(objFolder) <> "Nothing" And _
    IsInDefaultStore(objFolder) Then
    Set Item.SaveSentMessageFolder = objFolder
    End If
    Set objFolder = Nothing
    Set objNS = Nothing
    End Sub

    Public Function IsInDefaultStore(objOL As Object) As Boolean
    Dim objApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objInbox As Outlook.MAPIFolder
    On Error Resume Next
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
    Select Case objOL.Class
    Case olFolder
    If objOL.StoreID = objInbox.StoreID Then
    IsInDefaultStore = True
    End If
    Case olAppointment, olContact, olDistributionList, _
    olJournal, olMail, olNote, olPost, olTask
    If objOL.Parent.StoreID = objInbox.StoreID Then
    IsInDefaultStore = True
    End If
    Case Else
    MsgBox "This function isn't designed to work " & _
    "with " & TypeName(objOL) & _
    " items and will return False.", _
    , "IsInDefaultStore"
    End Select
    Set objApp = Nothing
    Set objNS = Nothing
    Set objInbox = Nothing
    End Function

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Send/Store (Outlook XP)

    <P ID="edit" class=small>(Edited by jscher2000 on 19-Jul-06 09:20. )</P>Application_ItemSend is an event handler. Outlook is passing it crucial information that supplies the parameters in parentheses based on the context of the event:

    <code>Sub Application_ItemSend(ByVal Item As Object, _
    Cancel As Boolean)</code>

    For your macro, the first thing is, you can't have any parameters. Adding parameters makes it usable only from another macro, procedure or function. Instead, you would use a simple name like:

    <code>Sub MoveToFolder()</code>

    Then you would add a bit of code to determine the intended target of the action by looking at, for example, the Selection for the ActiveExplorer.

    Added: The proposed name "Send & File" suggests that the macro also needs the functionality of sending a message from the window in which you are composing it. That actually is a bit more complicated because usually that window closes after sending, so trying to then file the message may return an error that your CurrentInspector object (the message editor) no longer exists. You could reverse the order: (1) display the folder picker; (2) store the destination folder in the message's SaveSentMessageFolder property; (3) send the message.

    Added: Actually, your code does #1 and #2. I thought it moved the message. <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Send/Store (Outlook XP)

    See the code <!post=here,402534>here<!/post> - I think it does what you want, post back if not. (It's not exactly what you asked for but provides the same capability without having to create an additional button to the Send command buttons.)

    What are you trying to do with the IsInDefaultStore function? (Which, as Jefferson points out, is not functional as posted.)
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Send/Store (Outlook XP)

    Thanks, John.

    IsInDefaultStore is called by Application_ItemSend. I am under the impression that it checks to determine whether this is an email folder.

    Let me explain what I'm trying to do. We want to retain the Send button as it is, so that a user will click it, and the open "compose" email message will be sent and stored, as usual, in the Sent Items folder. We would also like to have a new "Send and File" button that will do what this macro does.... send the item and store it in the folder of the user's choosing. The code I was given (which is what I posted), takes over the the existing Send button. I understand that because of the name it's been given, this is to be expected.

    Can you suggest some code that I can use that will send the current "compose" email message and allow the user to select the folder for the sent item to be stored in?

    Many thanks,
    Richard

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Send/Store (Outlook XP)

    Richard, Outlook VBA has a 'DefaultItemType' for that purpose. You should be able cobble the code I referenced with a test for it, such as this untested aircode:

    Private Sub Send_Save()
    Dim fldrTarg As MAPIFolder
    With ActiveExplorer.CurrentItem
    If .Class <> olMail Then Exit Sub
    Set fldrTarg = Application.GetNamespace("MAPI").PickFolder
    If Not fldrTarg Is Nothing and fldrTarg.DefaultItemType = olMailItem Then
    .Save
    .Send
    .Move fldrTarg
    Else
    MsgBox "No Message Items Folder Selected"
    End If
    End With
    Set fldrTarg = Nothing
    End Sub

    The button you create is presumed to be in the draft message window only.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Send/Store (Outlook XP)

    Thanks, John.

    An error occurs on line 2, With ActiveExplorer.CurrentItem: "Object doesn't support the property or method." I don't know enough about Outlook to troubleshoot this... can you help?

    Thanks,
    Richard

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Send/Store (Outlook XP)

    My mistake, that should have been ActiveInspector. Still has a problem, let me work on it.
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Send/Store (Outlook XP)

    Again, thank you.

    The last bit of code you sent showed up in my inbox, but does not appear here on the site.

    This seems to work without error, but it is not saving to the target folder. If I step through the code, the target folder appears to be read correctly after PickFolder. I even added a MsgBox to display the name of the folder. The folder I selected displays in the MsgBox, but the email is stored in Sent Items folder.

    Interestingly, when I step through the code, it quits after the .Move line.... does not continue through the remainder of the Sub.

    Any ideas about this?

    Thanks,
    Richard

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Send/Store (Outlook XP)

    The .Send line loses the message object, and the .Move code fails. I started on figuring that problem out, but had to get back to what they pay me for.
    -John ... I float in liquid gardens
    UTC -7ąDS

  10. #10
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Send/Store (Outlook XP)

    I figured that was the case... once the email is sent, there's no longer an object to work with. If you can offer some insight on where to go from here, it would be greatly appreciate.

    Thanks so much,
    Richard

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Send/Store (Outlook XP)

    <P ID="edit" class=small>(Edited by jscher2000 on 19-Jul-06 13:11. Cleaned up some code comments.)</P>This replaces my other post with code that is better from a teaching perspective.

    I think John must have been working on a different approach. Adapting your original code would be along these lines:

    <code>Sub SendAndFile() 'new name with no parameters
    Dim objNS As NameSpace
    Dim objFolder As MAPIFolder
    Set objNS = Application.GetNamespace("MAPI")
    Set objFolder = objNS.PickFolder
    If TypeName(objFolder) <> "Nothing" And _
    IsInDefaultStore(objFolder) Then
    Dim Item As Outlook.MailItem 'no "Item" supplied by Outlook, so need to create it
    Set Item = Application.ActiveInspector.CurrentItem
    Set Item.SaveSentMessageFolder = objFolder
    Item.Send ' Send the message immediately
    Set Item = Nothing
    End If
    Set objFolder = Nothing
    Set objNS = Nothing
    End Sub</code>

    That still uses the second function, which I don't really understand so I didn't try to replace it with anything.

    If you open a message that was sent to you and run this, nonsensical things happen...

  12. #12
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Send/Store (Outlook XP)

    Thanks. This functions as I'd like it to. I was wondering if this would leave the "file" folder set to the user's choice, and I see that it does not.

    The nagging question, of course, is how to avoid the annoying security warning that Outlook displays: someone is trying to send an email message on my behalf. I'm familiar with Redemption, but I think that only skirts the security issue when Contact/email address info is involoved, not with actually sending messages. My guess is that this cannot be avoided unless the code is packaged in an Outlook Add-In. Am I correct?

    Thanks again,
    Richard

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send/Store (Outlook XP)

    You could use the free add-in ClickYes; it automatically clicks Yes (hence the name) in the security dialogs. It would have to be installed on each user's PC.

  14. #14
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Send/Store (Outlook XP)

    I've used ClickYes.... I think that it's "reach" is too broad for the IT folks to accept.

    Richard

  15. #15
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Send/Store (Outlook XP)

    I was getting near your approach but my "Set SaveSentMessageFolder = objFolder" piece did not error out, but wasn't working for me, possibly because I have a Rule which moves all Sent files to another location.

    You might simplify this:

    If TypeName(objFolder) <> "Nothing" And _
    IsInDefaultStore(objFolder) Then

    to:

    If TypeName(objFolder) <> "Nothing" And _
    objFolder.DefaultItemType = olMailItems Then
    -John ... I float in liquid gardens
    UTC -7ąDS

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •