Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Canton, Ohio, USA
    Posts
    270
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Outlook Rules & Automatic File Save (Outlook XP )

    I receive e-mail messages from our voice message server that have a wav file attached. I want to have this e-mail sent to a particular folder upon arrival...which can be accomplished easily through the rules feature. But I also want to copy the attachment [i.e. there should always be only one attachment..the wav file] automatically to a folder, say G:voice messagesdatabase ???.wav. The path and folder will always be the same and I do not need to re-name the wav file...merely copy it as named in the e-mail to the fixed path /folder name.

    I am confused as to how to write the script and where it goes in Outlook...I have noticed that the rules wizard will permit the selection of a script--but I have no knowledge on how to do this...I have looked through the lounge and Slipstick----without success as to a automatic script approach. I have found several commercial software applications [through Slipstick site] that seem to do what I want...but I just can't believe that it would be too hard to merely copy a file attached to the e-mail to another location upon arrival---especially when the folder path is always the same and the filename does not need modified either---thus avoiding any program logic...it is merely a vanilla file copy. Any advice is appreciated. THANKS.

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

    Re: Outlook Rules & Automatic File Save (Outlook XP )

    Activate the Visual Basic Editor in Outlook (Alt+F11)
    Select Insert | Module.
    Paste the following code into the module:

    Sub SaveAttachment(itm As MailItem)
    If itm.Attachments.Count > 0 Then
    itm.Attachments(1).SaveAsFile _
    "G:voice messagesdatabase" & att.FileName
    End If
    End Sub

    The name of this procedure is not really important, but it must take a MailItem as argument; the rule will pass the e-mail to the procedure in this argument.
    Switch back to Outlook.
    Create a new rule and start from a blank rule.
    Select the option to check mail as it arrives, then click Next.
    Specify the way you can pick out the voice mail messages, then click Next.
    Tick the option to run a script, then click script in the lower box. You'll see the procedure you just created (preceded by something like Project1.)
    Select it, then click OK.
    Click Next and follow the rest of the instructions.

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

    Re: Outlook Rules & Automatic File Save (Outlook XP )


  4. #4
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Canton, Ohio, USA
    Posts
    270
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Outlook Rules & Automatic File Save (Outlook XP )

    Hans,
    Thanks for the advice and pointer to the MS site...I will read through the MS link and work further on making your code work this weekend. Again, thank you very much!! I really do appreciate your contribution to the lounge...take care.

  5. #5
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Canton, Ohio, USA
    Posts
    270
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Outlook Rules & Automatic File Save (Outlook XP )

    Hans,
    The code worked great....no surprise there. I have two follow-up questions.

    When I was just processing the rule [without copying the file to another location], the rule would fire even if Outlook wasn't open. I have noticed that the script will only fire when my Outlook is open...but it seems that the script itself gets saved in Exchange as I "see" the script when I go to a different pc in our network and access my mailbox. Is there any way to have the rule---plus your script run from Exchange and not be dependent on Outlook being open for my e-mail account? I am trying to make this work---so that the rule & script will process even when I am away unexpectantly from the office and my outlook is closed.

    Second question involves creating a 30 second delay at the beginning of the script. The reason for this request is that two e-mails with wav file attachments came into my box within 15 seconds [I actually never thought this would happen---as I usually only get 5 all day]. What happened is that the script fired on the second e-mail before the voice recognition system had begun to process the first wav file...Through some additional simulation, I have timed this process out and need a 30 to 40 second delay in the copy script to solve my problem. Can I just use a counter variable say from 1 to 1000 to simply cause a lapse in time prior to processing the copy file syntax in your code? I am struggling in researching code syntax as I believe I need to be using VB script and not VBA for Outlook....I know there should be a "delay" command--I am probably not looking at it properly.

    Thanks for your patience....I always try to learn about a process rather than using the lounge as a "quick" fix for a problem...take care.

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

    Re: Outlook Rules & Automatic File Save (Outlook XP )

    The code I posted is stored in a file with extension .otm (probably VbaProject.OTM) in your profile. If you have a roaming profile, the code will be available wherever you log in to the network. But since the code resides on a local PC, the rule automatically becomes a client-side rule that is only executed when Outlook is running. For more info, see Server-based vs. client-based rules.

    Don't use a loop to delay code. Instead, use the Sleep function. Place the following code at the top of the module, below Option Explicit if you have that, but above all Subs and Functions:

    Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

    Use it like this in your code to wait for 30 seconds (30,000 ms):

    Call Sleep(30000)

Posting Permissions

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