PDA

View Full Version : Repurposed Save Command - Error Handling



bstephens
07-28-2010, 12:33 AM
I re-purposed my "save" command as follows:

'REPURPOSED SAVE COMMAND - Automatically updates the field upon a file SAVE event
Sub FileSave()
ActiveDocument.Save
End Sub

'Callback for FileSave onAction
Sub rxFileSave_repurpose(control As IRibbonControl, ByRef cancelDefault)
Call FileSave
Call UpdateAllFields
End Sub
This code works fine if you save the document, but if it is a new document (not yet saved) and you hit "cancel", it gives the error:


Run-time error '4198':

Command failed
Is there a way to make the function just exit out if the user hits cancel and the document is not yet saved, instead of getting the error 4198?

Best,
Brian

fumei
07-28-2010, 08:31 AM
.Saved is boolean - True or False
If ActiveDocument.Saved = False Then
MsgBox "not saved."
' or Exit Function...except you are not using a Function
End if




'REPURPOSED SAVE COMMAND - Automatically updates the field upon a file SAVE event
Sub FileSave()
ActiveDocument.Save
End Sub
Your comment is incorrect. The Sub FileSave() above does NOT update any fields. There is no instruction within FileSave to do that.