Compile error while declaring close

萝らか妹 提交于 2019-12-11 01:21:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!