VBA - Bypassing Error Report When openning A File

Lotus Cars

Board Regular
Joined
Feb 4, 2011
Messages
55
Hi folks,

Apologies, but this is a bit long winded.

I have an excel file, that when I open the normal way (File, open) will always come up with the following error report

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>"excel found unreadable content in xxx.xls. Do you want to recover the contents of this workbook?"</o:p>
<o:p></o:p>
<o:p>So I hit yes, and get</o:p>
<o:p></o:p>
<o:p>"File error: data may have been lost"</o:p>
<o:p></o:p>
<o:p>so I hit OK, and get</o:p>
<o:p></o:p>
<o:p>"Errors were detected in xxx.xls but Microsof Office excel was able to open the file by making the repairs listed below - renamed invalid sheet name"</o:p>
<o:p></o:p>
<o:p>So I hit close, and the spreadsheet opens fine.</o:p>
<o:p></o:p>
<o:p>However, when I try and open the same file through a macro</o:p>
<o:p></o:p>
<o:p>Workbooks.OpenText filename:= "I:\Accts Central\Group Accounts 2011-12\Forecasts\xxx.xls</o:p>
<o:p></o:p>
<o:p>it just has a strop, and gives me a </o:p>
<o:p></o:p>
<o:p>"</o:p><o:p>runtime error 1004 Method OpenText of object workbooks faild"</o:p>
<o:p></o:p>
<o:p>message and stops. </o:p>
<o:p></o:p>
<o:p>I have it wrapped in a Application.DisplayAlerts = False blanket to try ad stop this coming up, but it doesn't.</o:p>
<o:p></o:p>
<o:p>Is there any way of circumventing the error message?</o:p>
<o:p></o:p>
<o:p>Any advice / help would be grateful.</o:p>
<o:p></o:p>
<o:p>Cheers,</o:p>
<o:p></o:p>
<o:p>Lotus Cars</o:p>
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Sorry, I meant

Workbooks.Open filename:= "I:\Accts Central\Group Accounts 2011-12\Forecasts\xxx.xls"

Cheers,

Lotus Cars
 
Upvote 0
And does error appear when you open workbook manually?
 
Upvote 0
Yeah, as I tried to describe in my long winded way, openning it manually brings up the error message, but ultimately it will open the file, and the file is OK.
 
Upvote 0
Try to save it under different name. If you have Excel 2007/2010 then it's possible that you have some content inside your Excel file which Excel ignores every time. To watch this, you need to look through the content of your workbook.
 
Upvote 0
Resaved it, and the macro now picks it up. Will just have to remember to do that each time I create the xxx.xls spreadsheet.

Cheers for your help.
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,225
Members
452,896
Latest member
IGT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top