EXCEL VBA: 忽略word文档错误,阅读内容

EXCEL VBA: Ignore word document errors and read content

I am writing VBA code to read the word document content and paste them in excel sheets, everything is fine,

but while reading multiple word documents Some of the word document shows the error messages for example "Word could not fire an event", due to this the program hangs up.

Can anyone suggest a VBA code to ignore these type of error and read the word content.

I have my placed code below.

Dim oDoc As Word.Document
Set oDoc = GetObject("D:6013(1).doc")
str = oDoc.Content.text 
MsgBox (str)
oDoc.Close (0)

Based on the answers

Dim wdApp As Word.Application
Dim oDoc As Word.Document
Set wdApp = CreateObject("word.Application")
wdApp.DisplayAlerts = **** 'unable to give false here, it shows only three options wdAlertsNone, wdAlertsMessageBox, wdAlertsAll
Set oDoc = wdApp.Documents.Open("D:6013(1).doc")
str = oDoc.Content.text
oDoc.Close (0)
wdApp.Quit False

尝试

Application.DisplayAlerts = False

如果您使用其他应用程序对象,则必须在该对象上设置 DisplayAlerts = False

Dim app As Word.Application
Set app = CreateObject("Word.Application")
Dim oDoc As Word.Document
app.DisplayAlerts = wdAlertsNone
On Error Resume Next
Set oDoc = app.Documents.Open("D:6013(1).doc")
On Error GoTo 0
str = oDoc.Content.text 
MsgBox (str)
oDoc.Close (0)
app.Quit

注意:On Error Resume Next 语句是有风险的。它希望您知道跳过的错误。如果错误损坏了文档,您可能无法阅读该文档的内容(在下一行),但是语句 On Error GoTo 0 将错误处理重置为默认值,因此如果您在该行中遇到错误, 将显示错误。