Dim oDoc As Word.Document
Set oDoc = GetObject("D:\176013(1).doc")
str = oDoc.Content.text
MsgBox (str)
oDoc.Close (0)
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:\176013(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:\176013(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
将错误处理重置为默认值,因此,如果在该行中收到错误,错误将被显示。