DocumentBeforeSave Throwing error pls help

A

Andrew M

Hi

I am doing a MS Office XP/2003 addin. However, one problem that makes me wonder is this one. I capture the DocumentBeforeSave Function and use this code. The problem if I respond to this function with a Cancel, or a No and then when I save, press Cancel, I get an Error 'Command Failed'

Am I just not doing this right or what?

Thanks

Andrew



Public Sub oApp_DocumentBeforeSave(ByVal Doc As Word.Document, SaveAsUI As Boolean, Cancel As Boolean)
' File Before Save
Dim intUserResponse As Integer

On Error GoTo ErrorHandler

If Doc.Name = "Normal.dot" Then Exit Sub

If m_blnImFiling = True Then
Exit Sub
End If

If m_blnIntegrate = True And m_blnSA_Int = True Then

'File to Foremost
intUserResponse = MsgBox("Would you like to file this document?", vbQuestion + vbYesNoCancel, "File Document?")

Select Case intUserResponse

Case vbCancel
Cancel = True

Case vbYes
Cancel = True
g_bln_SAflag = True

Case vbNo
'Do not File - Save Locally
SaveAsUI = True
Cancel = False
g_bln_SAflag = False

End Select

End If

Exit Sub
ErrorHandler:
ErrorReporter "Word_SaveAs", Error, Err, , True, True
Exit Sub
Resume
End Sub
 
J

jabroni

This may be a shot in the dark. I receieved the exact same error whe
writing my code for VBA. Like yourself, the error generates upo
selecting the Cancel button and I was at a loss because the code loo
fine. It turned out for me to be the Error Trapping option. Thi
option is available in your Visual Basic Editor under Tools - Options
General. There are 3 options there (1)Break on All Errors: (2)Break i
Class Module :(3)Break on Unhandled Errors. I intentionally set thi
option to (1)Break on All Errors in order to view the actual VB Runtim
error whenever I am trying to bebug code. Once I changed this to (3
'Break on Unhandled Errors' the error vanishes. Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top