VBA bypass Unreadable Content Warning

jscranton

Well-known Member
Joined
May 30, 2011
Messages
707
I have a line of code that sets a workbook variable to each workbook in a folder and then runs some additional code over each workbook.

Occassionally I will get an error (Run time 1004) on the line below. If I try to open the workbook throwing the error it almost always has an unreadable content warning when I open it manually. I have turned off Display Alerts but is there something else I need to do to bypass this error?


Code:
        Application.DisplayAlerts = False
        Set wb = Workbooks.Open(fileName:=myPath, UpdateLinks:=False)
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You'll need to use error handling in your code. The example below is me making a guess at how your method is structured.

Code:
Sub EditWorkbook(myPath As String)

Dim wb As Workbook


  Application.DisplayAlerts = False
  
  On Error GoTo WorkbookOpenFailure
  Set wb = Workbooks.Open(Filename:=myPath, UpdateLinks:=False)
  
  Application.DisplayAlerts = True
  
  On Error GoTo OtherError
  'The rest of the code for editing the workbook
  
Exit Sub


WorkbookOpenFailure:
  MsgBox "The Workbook didn't open probably due to unreadable content. :( :(", vbExclamation, "Workbook Open Failure"
  Application.DisplayAlerts = True


Exit Sub


OtherError:
  MsgBox "Something else went wrong that I should probably give you more information about. #MacroTrolling", vbExclamation, "Other Error"
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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