I’ve come across a nasty little bug in Excel VBA’s .OpenText method.. It errors on opening any text or CSV file when the first two letters are upper-case “ID”. Here is the article from MS so you know I’m not crazy: http://support.microsoft.com/kb/323626
So, I’m trying to figure out a workaround that does NOT involve copying the entire file just to re-name the first header. I am working with some large text files and this would be an unsatisfactory last resort.
I’ve tried On Error Resume Next before the .OpenText call but that didn’t work.. Has anybody come across this and found a simple solution I’m missing? Is there a way to just crack open the first line and find/replace inside of a text file? Or extra parameters to .OpenText I could use?
I wrote this for you. Just call it passing the filepath prior to attempting to open it. I deliberately wrote this with late binding, so no references are required. it will add an apostrophe to the beginning of the file, if the file starts with “ID”.