efddale
03-20-2003, 01:16 PM
Hi everyone,
I'm relatively new to Exce VBA programming. I'm trying to do something that I thought would be relatively simple. I want to use the Workbook_BeforeClose event to change the fill color of a range of cells before Excel closes. My code works fine if Excel is closed using either the standard "exit button" in the upper right hand corner or the File-Exit method. However, I also want to be able to exit using a separate macro located either on "Sheet1" or in a module. When I close Excel using the separate code, the Workbook_BeforeClose event fires normally but I get an error involving the code line containing Interior.ColorIndex. I don't understand why the code works one way and not the other. I would appreciate any help that I can get. My code is as follows:
Thanks, efddale
Module code:
Sub Program_Exit()
Application.Quit
End Sub
Before_Close code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim TestRange As Range
Set TestRange = Range("A1:J1")
TestRange.Interior.ColorIndex = 6
I'm relatively new to Exce VBA programming. I'm trying to do something that I thought would be relatively simple. I want to use the Workbook_BeforeClose event to change the fill color of a range of cells before Excel closes. My code works fine if Excel is closed using either the standard "exit button" in the upper right hand corner or the File-Exit method. However, I also want to be able to exit using a separate macro located either on "Sheet1" or in a module. When I close Excel using the separate code, the Workbook_BeforeClose event fires normally but I get an error involving the code line containing Interior.ColorIndex. I don't understand why the code works one way and not the other. I would appreciate any help that I can get. My code is as follows:
Thanks, efddale
Module code:
Sub Program_Exit()
Application.Quit
End Sub
Before_Close code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim TestRange As Range
Set TestRange = Range("A1:J1")
TestRange.Interior.ColorIndex = 6