Jump to content

[Solved]Opening CSV in Excel


Recommended Posts

Morning everyone!

I am trying to figure out why a certain csv is not opening in the correct format with _Excel_BookOpenText().

I use the code below to open a csv into excel and from there I can sort and filter the data much easier. My issue is it does not open the file in the correct format, but when I open the csv with excel normally (right-click, open  with, excel) excel opens the csv in the correct format. I use this code with many other csv's and I never had this issue before, and as far as I can tell, the format of the csv doesn't have any abnormalities than the other ones I work with. 

I have also attached a csv I also use that has the same format but works. Also I am using Microsoft Excel 2010 on a 32-bit Windows 7 machine.

;Open the csv in excel
Global $sPathTXT = "Path to .txt"
Global $sPathExcel = "Path to save .xlsx"
Global $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Global $oWorkbook = _Excel_BookOpenText($oExcel, $sPathTXT)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_BookSaveAs($oWorkbook, $sPathExcel)
If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error saving the workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Hopefully someone has had a similar experience and knows a quick fix? I feel I may just be out of luck with this data :(

Thanks guys!

DoesNotWork.txt

ThisWorks.txt

Edited by Davidowicza
Removed full paths to files
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...