VBA to take a CSV Outlook Attachment and Save it as XLSX

  • Hi, So each day I get emails with attachments in csv form but I need them to be in xlsx form when saved. So what I am trying to do is use a rule within outlook that will take the CSV file, convert it, and save it as a xlsx in another folder. Here is what I have so far but it doesn't seem to function properly.


  • Have to look at the below line.


    Code
    replace this
    myWB.SaveAs saveFolder & DateFormat & " " & objAtt.FileName & "x", FileFormat:=51
    with
    myWB.SaveAs saveFolder & DateFormat & " " & objAtt.FileName & ".xlsx", FileFormat:=51

    While that was a mistake on my part, it still does not solve the overall issue. A File explorer dialog box pops up for less than a second and disappears when running the rule.

  • Cs you may want to throughly check ur code.


    Code
    myFileName = mySaveFolder & "Inventory Balance" & " " & DateFormat

    with

    Code
    myFileName = mySaveFolder & "\Inventory Balance" & " " & DateFormat

    This becomes a redundant slash if my save folder path ends with / ? It doesn't in my code example but the actual path does.

  • Mate, Unless you provide the actual code or an sample workbook it will be difficult for us to come to any conclusion.

    Minus the folder path which is just "G:\\WA3223\WA\Inventory Archive\2019\Dec\" The code posted is exact.

  • please share the screen shot of the error

    That's what is throwing me, it doesn't give an error. When run it pops up a file explorer window for half a second and closes. Even when told to stop on all errors it runs the same. So as much as I would like to in order to help you out with what's going on, there's just no screenshot to take.


    If you would like I can screenshot the code from the actual window and then do my best to nab the file explorer window but it's not likely.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!