EXCEL VBA: Ignore word document errors and read content -
i writing vba code read word document content , paste them in excel sheets, fine,
but while reading multiple word documents of word document shows error messages example "word not fire event", due program hangs up.
can suggest vba code ignore these type of error , read word content.
i have placed code below.
dim odoc word.document set odoc = getobject("d:\176013(1).doc") str = odoc.content.text msgbox (str) odoc.close (0)
based on answers
dim wdapp word.application dim odoc word.document set wdapp = createobject("word.application") wdapp.displayalerts = **** 'unable give false here, shows 3 options wdalertsnone, wdalertsmessagebox, wdalertsall set odoc = wdapp.documents.open("d:\176013(1).doc") str = odoc.content.text odoc.close (0) wdapp.quit false
try
application.displayalerts = false
if use other application objects, have set displayalerts = false
on object.
dim app word.application set app = createobject("word.application") dim odoc 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
note: on error resume next
statement risky. expects know skipped error. if error corrupts document, may not able read contents of document (in next line), statement on error goto 0
resets error handling default, if error in line, error shown.
Comments
Post a Comment