Link to home
Create AccountLog in
Avatar of namerg
namergFlag for United States of America

asked on

An automated way to download an xlsx attachment and convert it into a CSV

Hello,
I would like to know an automated way to download an xlsx attachment and convert it into a CSV and drop it into a network share.

Thanks
Avatar of vivigatt
vivigatt
Flag of France image

An xlsx attachment to an e-mail?
Avatar of namerg

ASKER

Sorry, i forgot to add that. Yes, download the attachment from an outlook email.
ASKER CERTIFIED SOLUTION
Avatar of vivigatt
vivigatt
Flag of France image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of namerg

ASKER

I have office Pro Plus 2010 and do not see the Macros option. :(
I don't know where they are in Office 2010, but they should be somewhere!
http://www.addictivetips.com/windows-tips/macros-in-office-excel-2010/

They could be disabled by default though:
http://www.nirmaltv.com/2009/12/28/how-to-enable-macros-in-office-2010/
Avatar of namerg

ASKER

hmm nope, did not work. No idea how to make the Macros option appear.
Avatar of namerg

ASKER

Vivigatt, it is not for excel. The macro option is for Outlook, not excel. Do you understand me?
SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of namerg

ASKER

U GOT IT @ve3ofa
You should be able to use automation (macros) in Excel and Outlook, and even call Outlook from Excel. I don't think you can manipulate .xlsx files from Outlook. You coudl even use Outlook "from excel", using a macro and some "outlook object"
Avatar of namerg

ASKER

I am getting a type mismatch error, run time 13 on line 19
Sub SaveAttachments()

    Dim olApp As Outlook.Application
    Dim olNs As NameSpace
    Dim Fldr As MAPIFolder
    Dim MoveToFldr As MAPIFolder
    Dim olMi As MailItem
    Dim olAtt As Attachment
    Dim MyPath As String
    Dim i As Long

    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
    Set MoveToFldr = Fldr.Folders("CompSurv")
    MyPath = "C:\My Documents\Completed Survey\"

    For i = Fldr.Items.Count To 1 Step -1
        Set olMi = Fldr.Items(i)
        If InStr(1, olMi.Subject, "Completed Survey") > 0 Then
            For Each olAtt In olMi.Attachments
                If olAtt.FileName = "Test.xls" Then
                    olAtt.SaveAsFile MyPath & olMi.SenderName & ".xls"
                End If
            Next olAtt
            olMi.Save
            olMi.Move MoveToFldr
        End If
    Next i

    Set olAtt = Nothing
    Set olMi = Nothing
    Set Fldr = Nothing
    Set MoveToFldr = Nothing
    Set olNs = Nothing
    Set olApp = Nothing

End Sub

Open in new window

Capture.PNG
Avatar of namerg

ASKER

I got it. I have to set line 7 as Dim olMi As Variant
Avatar of namerg

ASKER

Hmm, this is new "You must assign a minimum of 20 points to all answers." I cannot submit after choosing the answers and close this case
You must assign a minimum of 20 points to all answers  should probably read
You must assign a minimum of 20 points to all selected answers
Avatar of namerg

ASKER

hmm, that is new...i never had to do that
Avatar of namerg

ASKER

Does not let me add the 20 points....
Hi, namerg.

Yes, this can all be done from within Outlook.  The code required is surprisingly simple.  Do you want this to work automatically (e.g. like a rule) or do you want to select a message and run the macro manually?
Avatar of namerg

ASKER

I am using Accept Multiple Solutions
Avatar of namerg

ASKER

I think it worked now