![]() |
How to skip "unrecognizable" msg when opening Workbook
I use the following code to try and open a downloaded csv file:
======================== Function OpenCSVFile(csvFileName) As Boolean On Error GoTo FailedOpen Application.Workbooks.Open csvFileName OpenCSVFile = True Exit Function FailedOpen: OpenCSVFile = False End Function ================== Sometimes the CSV is not guaranteed to be readable, and when it can't open, a dialogue comes up saying "This file is not in a recognizable format." I would hope this would be caught by "On Error", but it doesn't catch it. It's a large batch process and I don't want it to be halted by a bad CSV file, i want the error to be logged and continue. Any idea on how I can prevent this? A way to supress the dialogue, or to check a file for validity before even trying to open it? Thanks, Mayhew |
How to skip "unrecognizable" msg when opening Workbook
I don't know much, but you might want to try
application.displayalerts=false/true 'false at the beginning, true at the end at the beginning/end of the sub? I don't know much about formulas, so I don't know if this would work with it. "Mayhew" wrote: I use the following code to try and open a downloaded csv file: ======================== Function OpenCSVFile(csvFileName) As Boolean On Error GoTo FailedOpen Application.Workbooks.Open csvFileName OpenCSVFile = True Exit Function FailedOpen: OpenCSVFile = False End Function ================== Sometimes the CSV is not guaranteed to be readable, and when it can't open, a dialogue comes up saying "This file is not in a recognizable format." I would hope this would be caught by "On Error", but it doesn't catch it. It's a large batch process and I don't want it to be halted by a bad CSV file, i want the error to be logged and continue. Any idea on how I can prevent this? A way to supress the dialogue, or to check a file for validity before even trying to open it? Thanks, Mayhew |
How to skip "unrecognizable" msg when opening Workbook
Thanks for the suggestion. I neglected to mention that if you click past the
dialog , the corrupt file opens anyway, and I don't want my script running on the garbage file. So I need some way of knowing in my code that the error has occurred, and skipping over that file. "comparini3000" wrote: I don't know much, but you might want to try application.displayalerts=false/true 'false at the beginning, true at the end at the beginning/end of the sub? I don't know much about formulas, so I don't know if this would work with it. "Mayhew" wrote: I use the following code to try and open a downloaded csv file: ======================== Function OpenCSVFile(csvFileName) As Boolean On Error GoTo FailedOpen Application.Workbooks.Open csvFileName OpenCSVFile = True Exit Function FailedOpen: OpenCSVFile = False End Function ================== Sometimes the CSV is not guaranteed to be readable, and when it can't open, a dialogue comes up saying "This file is not in a recognizable format." I would hope this would be caught by "On Error", but it doesn't catch it. It's a large batch process and I don't want it to be halted by a bad CSV file, i want the error to be logged and continue. Any idea on how I can prevent this? A way to supress the dialogue, or to check a file for validity before even trying to open it? Thanks, Mayhew |
All times are GMT +1. The time now is 12:28 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com