|
|
Question : Error message suppression in word
|
|
Word produces an error message even though error handling code has been setup. Is this possible to suppress?
The macro is designed to open word documents on the server. It macro works fine when a document exists but if one is not found, an error number 1078 appears "This file could not be found".
The error message appears immediately after the line of code has been executed. The line that is prompting the error is as follows: WordBasic.fileopen Name:=PathDir & "\Base Training\" & ComboBox1.Text & "_training_gradesheet.doc"
The code then continues down and runs the error handling code, giving a similar message "This file could not be found" I tried using 'Canceldisplay' but without success.
|
Answer : Error message suppression in word
|
|
you can create a file opener function that returns the doc if it's there and not íf it's not
Sub test() Dim oDoc As Document 'get the doc by passing the path Set oDoc = OpenFileTest(PathDir & "\Base Training\" & " " & "_training_gradesheet.doc") 'test for empty object If oDoc Is Nothing Then Exit Sub 'do the rest of your processing with the oDoc object MsgBox "hello"
'cleanup Set oDoc = Nothing End Sub
Public Function OpenFileTest(ByVal sfile As String) As Document
On Error GoTo errhandle Application.DisplayAlerts = wdAlertsNone Set OpenFileTest = WordBasic.fileopen(Name:=sfile) Application.DisplayAlerts = wdAlertsAll Exit Function errhandle: Err.Clear Exit Function End Function
hope this helps a bit
|
|
|
|