问题
Platform : Microsoft Visual Basic 6.5 and MS Excel 2007
I am trying to do a macro to do some editing to an excel enable file. Done research on how to close the Excel file without saving. The webpage teaches me to put declaration before I can use the method. I insert copy the command in and try to compile. Got compilation error, expected end of statement. Anyone know what's wrong with the declaration?
Public Overridable Sub Close ( _
<OptionalAttribute> SaveChanges As Object, _
<OptionalAttribute> Filename As Object, _
<OptionalAttribute> RouteWorkbook As Object _
)
Private Sub WorkbookClose()
Me.Close(False, False)
End Sub
回答1:
If its macro in excel copy the below code to thisworkbook section of code.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Me.Close False
End Sub

回答2:
Double click on "ThisWorkbook" and enter the following code:
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
MsgBox "Save Is Not Allowed"
End Sub
来源:https://stackoverflow.com/questions/15779333/compile-error-while-declaring-close