Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Dec 2002
    Location
    Lake Forest, California, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automating File/Save (XP)

    I'd like to automate, either using a rule (preferably) or if I have to, a macro button, saving selected emails from my inbox to a directory on my hard drive. Could any kind soul post a code snippet that might help?

    I know there are 3rd party add-ins which can do this, I want to do it myself.

    Ideally I'd like to write an add-in using VB, but reading forum posts it seems that this may not be easy - many references to the fact it *must* be C++ exist (although I don't see why).

    Thanks all!

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

    Re: Automating File/Save (XP)

    Andrew beat me to the punch, but here's some code to save a message to disk as RTF from a button. See the SaveAs Method for alternatives for the type of file to be saved. One hassle I ran into is that Outlook's Save As dialog removes illegal file characters, but the SaveAs method doesn't, and you will have to. So I recycled an old function "StripTheseChars" I wrote to clean up the filename to be saved. I also use Sue Moshers' GetCurrentItem function in <post#=205303>post 205303</post#>.

    Sub SaveMsgToFile()
    Dim objItem As Object
    Dim strFName As String
    Const strPath As String = "C:My DocumentsMail" ' don't forget closing slash
    Set objItem = GetCurrentItem ' using Sue Mosher's function
    If Not objItem Is Nothing Then
    If TypeName(objItem) = "MailItem" Then ' contacts can also saved as OFT
    strFName = StripTheseChars(objItem.Subject & ".rtf", ":/*|") ' take out illegal filename characters
    objItem.SaveAs strPath & strFName, olRTF
    Else
    MsgBox "No Mail Item Selected", vbExclamation
    End If
    End If
    End Sub

    Function StripTheseChars(ByVal strInput As String, _
    ByVal strChars2Del As String) As String
    Dim lngPos As Long, lngInputSLen As Long, lngDelCharsLen As Long, lngCounter As Long
    Dim strCurrentChar2Del As String
    lngDelCharsLen = Len(strChars2Del)
    For lngCounter = 1 To lngDelCharsLen
    strCurrentChar2Del = Mid(strChars2Del, lngCounter, 1)
    Do While InStr(strInput, strCurrentChar2Del)
    lngInputSLen = Len(strInput)
    lngPos = InStr(strInput, strCurrentChar2Del)
    strInput = Left(strInput, lngPos - 1) & Right(strInput, lngInputSLen - lngPos)
    Loop
    Next lngCounter
    StripTheseChars = strInput
    End Function
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    New Lounger
    Join Date
    Dec 2002
    Location
    Lake Forest, California, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating File/Save (XP)

    Awesom Andrew, many thanks.

  4. #4
    New Lounger
    Join Date
    Dec 2002
    Location
    Lake Forest, California, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating File/Save (XP)

    Thanks John, I think that's what I need to get me started.

  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: Automating File/Save (XP)

    Andrew, what does

    Reformat MyFile

    do? I can't see another function being called, and I can't find this as a native Method in OL2000. Is it an XP Method?
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    New Lounger
    Join Date
    Dec 2002
    Location
    Lake Forest, California, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating File/Save (XP)

    FWIW I guessed this was a part of Andrew's app, I have XP and there's no Reformat keyword coming up.

  7. #7
    5 Star Lounger
    Join Date
    Oct 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    621
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating File/Save (XP)

    John

    Actually - it was going to be a piece of my code - but I hadn't written it yet <img src=/S/blush.gif border=0 alt=blush width=15 height=15>. I'll delete it from the previous code.

  8. #8
    5 Star Lounger
    Join Date
    Oct 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    621
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating File/Save (XP)

    I cannot see a reason for it to be a C++ program either

    There are two fairly easy options
    a) write a snippet of VBA that looks for an appropriate mail message and saves it
    [img]/forums/images/smilies/cool.gif[/img] create a rule to move the item to a folder - then have a piece of VBA code that moves the folders content to disk - either as a macro button or as an event

    The challenge will be uniquely identifying and indexing the mail messages (and their attachments) on disk - rather than the actual save

    I've just cut a piece of code that isn't quite what you want - but works in a similar area - detecting messages and saving. It had exhibited an instability under 2002 SR2 - but I'm hoping that the recently released patch will address that <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Andrew

    Private Sub Application_NewMail()

    ' Identifies incoming mail that has an attachment that matches our target type
    ' if so, asks, and translates it to new format and save

    ' Change the following two constants as required to get things working right
    ' First is simply a list of valid extensions to trigger reformating action

    MyExts = ".txt.TXT.001"

    ' Second is the path for re-formatted files to go to

    MyPath = "C:TEMP"

    ' Preliminary setup to view new mail

    Set MyOlApp = CreateObject("Outlook.Application")
    Set MyNameSpace = MyOlApp.GetNamespace("MAPI")
    Set MyOlApp.ActiveExplorer.CurrentFolder = _
    MyNameSpace.GetDefaultFolder(olFolderInbox)

    ' Identify unread mail and deal with it

    With MyOlApp.ActiveExplorer.CurrentFolder
    For I = 1 To .Items.Count
    If .Items(I).UnRead = True Then
    For J = 1 To .Items(I).Attachments.Count
    MyFile = .Items(I).Attachments(J).DisplayName
    MyExt = Right(MyFile, 4)
    MyFile = Left(MyFile, Len(MyFile) - 4)
    If InStr(1, MyExts, MyExt, vbTextCompare) > 0 Then
    MyFile = InputBox("Shipping file detected" & vbCrLf & _
    "Press OK to reformat '" & MyFile & MyExt & "', Cancel to skip" _
    & vbCrLf & "(Change attachment name if necessary)", _
    .Items(I).Subject, MyFile)
    If MyFile <> "" Then
    MyFile = MyPath & "" & MyFile & "._B4"
    .Items(I).Attachments(J).SaveAsFile MyFile
    End If
    .Items(I).FlagStatus = olFlagComplete
    .Items(I).FlagRequest = MyFile
    .Items(I).FlagDueBy = Now()
    .Items(I).UnRead = False
    End If
    Next J
    End If
    Next I
    End With

    End Sub

  9. #9
    New Lounger
    Join Date
    Dec 2002
    Location
    Lake Forest, California, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automating File/Save (XP)

    Just thought I'd share - I managed to create a COM add-in for Outlook using VB (actually VB .Net) <img src=/S/yadda.gif border=0 alt=yadda width=15 height=15> . Here's a great article:

    http://msdn.microsoft.com/library/default....laddinvbnet.asp

    Keith.

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

    Re: Automating File/Save (XP)

    Thanks.

    See the Forum Help on Markup on how to make those links live:

    Style 1 <!t>wopr.com = Makes the given url into a clickable link http://wopr.com

    Style 2 <!t> Woody's Lounge = Only the url's description shows, like this Woody's Lounge

    Building Outlook 2002 Add-ins with Visual Basic .NET
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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