VBA: Save and Close vs Deactivate

Dragonmann

New Member
Joined
Apr 26, 2010
Messages
14
I have created a special worksheet template for filing new customer RFQs.

When the required information is filled in, a submit button appears.

When the button is pressed the document opens the log file, copies some info into it, and then saves and closes both programs.


The problem is I have cod in the Worksheet_Deactivate event, specifically unhiding the ribbon bar, but I have tried other code as a test. If there is any code in the Deactivate event I get "Run time Error '1004': Method 'Close' of object '_workbook' failed"


I was able to make it work by using Application.EnableEvents = False , but since this workbook is closing it leaves the events off, and messes up the next excel file I open.


Any suggestions of code to disable only the deactivate event, or just how to make it work in general?


This is the end of the submit code:

Code:
ActiveWorkbook.SaveAs Filename:="c:\workspace\RFQ" & RFQNumber & " - " & CompanyName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    Call SendMail((RFQNumber), (CompanyName), (RequestBy), (RFQDate))
    
    If ActiveWorkbook.FileFormat <> xlOpenXMLTemplateMacroEnabled Then
    
        ActiveSheet.Protect


    End If
    
    
    
    
    ActiveWorkbook.Unprotect
    
            ActiveWindow.DisplayGridlines = True
            ActiveWindow.DisplayHeadings = True
            Application.DisplayFormulaBar = True
            Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
    
    Application.EnableEvents = False
        
    ActiveWorkbook.Close SaveChanges:=False
    
    Application.EnableEvents = True

And this is the Deactivate code:

Code:
    Application.DisplayFormulaBar = True
    Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
In very general terms:

Code:
Public bAbort As Boolean
Sub DoStuff()

    bAbort = True
    
    'Do Stuff that will trigger EventTriggered
    
    bAbort = False

End Sub

and then in the event handler:

Code:
Sub EventTriggered()

    If bAbort Then Exit Sub
    
    'Handle event here
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top