Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slow opening of "in use" workbook Kurosh Excel Discussion (Misc queries) 1 November 9th 07 10:54 PM
"Running Virus Scan" ....On Opening Excel Workbook Dermot Excel Discussion (Misc queries) 1 August 30th 07 09:17 PM
How do I automatically "enable Macros" when opening a workbook RobertWNewson Excel Programming 1 April 11th 06 05:51 PM
Emptying cache or "history" before opening workbook windsurferLA Excel Programming 2 February 15th 05 06:30 PM
Adding "New" "Insert" "Delete" into a workbook to change from data 1 to data 2 etc Bob Reynolds[_2_] Excel Programming 0 March 4th 04 08:52 PM


All times are GMT +1. The time now is 10:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"