Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default Workbook_BeforeClose Question

I'm using this code to clear everything within the range of C14 to C21
(Sheet1) before my workbook closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
End Sub

I wonder why it doesn't work. The data still remain (in the cells) if I
open it again. Is it because some cells have data validation on it? And
they're data input is restricted?

Or is there another way of making this work?

Help. :)


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 146
Default Workbook_BeforeClose Question

Your code has to be in ThisWorkbook to work. If it's in a module, it won't
get executed.

"Sashi" wrote in message
...
I'm using this code to clear everything within the range of C14 to C21
(Sheet1) before my workbook closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
End Sub

I wonder why it doesn't work. The data still remain (in the cells) if I
open it again. Is it because some cells have data validation on it? And
they're data input is restricted?

Or is there another way of making this work?

Help. :)




  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,290
Default Workbook_BeforeClose Question


You need to save the workbook after clearing the cells.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Sashi"
wrote in message
I'm using this code to clear everything within the range of C14 to C21
(Sheet1) before my workbook closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
End Sub

I wonder why it doesn't work. The data still remain (in the cells) if I
open it again. Is it because some cells have data validation on it? And
they're data input is restricted?
Or is there another way of making this work?
Help. :)


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default Workbook_BeforeClose Question

Hi Dave,

My code is already in ThisWorkbook, so it shouldn't be a problem. :(
Hello Jim,

I already added the line:

Worksheets("Sheet1").Save

after clearing the contents, it still didn't work. :(

Sashi

"Jim Cone" wrote:


You need to save the workbook after clearing the cells.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Sashi"
wrote in message
I'm using this code to clear everything within the range of C14 to C21
(Sheet1) before my workbook closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
End Sub

I wonder why it doesn't work. The data still remain (in the cells) if I
open it again. Is it because some cells have data validation on it? And
they're data input is restricted?
Or is there another way of making this work?
Help. :)



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Workbook_BeforeClose Question

You cannot save a worksheet. You must save the workbook

Thisworkbook.save

or

ActiveWorkbook.save


Gord Dibben MS Excel MVP

On Wed, 25 Jul 2007 08:04:01 -0700, Sashi
wrote:

Hi Dave,

My code is already in ThisWorkbook, so it shouldn't be a problem. :(
Hello Jim,

I already added the line:

Worksheets("Sheet1").Save

after clearing the contents, it still didn't work. :(

Sashi

"Jim Cone" wrote:


You need to save the workbook after clearing the cells.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Sashi"
wrote in message
I'm using this code to clear everything within the range of C14 to C21
(Sheet1) before my workbook closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
End Sub

I wonder why it doesn't work. The data still remain (in the cells) if I
open it again. Is it because some cells have data validation on it? And
they're data input is restricted?
Or is there another way of making this work?
Help. :)






  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default Workbook_BeforeClose Question

Hi Gord,

I'm so sorry for being such a pain, but I tried your suggestion, leme show
you my whole code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
'ThisWorkbook.Save *I actually tried both*
ActiveWorkbook.Save
End Sub

These lines are in Sheet1. What else can I do?


"Gord Dibben" wrote:

You cannot save a worksheet. You must save the workbook

Thisworkbook.save

or

ActiveWorkbook.save


Gord Dibben MS Excel MVP

On Wed, 25 Jul 2007 08:04:01 -0700, Sashi
wrote:

Hi Dave,

My code is already in ThisWorkbook, so it shouldn't be a problem. :(
Hello Jim,

I already added the line:

Worksheets("Sheet1").Save

after clearing the contents, it still didn't work. :(

Sashi

"Jim Cone" wrote:


You need to save the workbook after clearing the cells.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Sashi"
wrote in message
I'm using this code to clear everything within the range of C14 to C21
(Sheet1) before my workbook closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
End Sub

I wonder why it doesn't work. The data still remain (in the cells) if I
open it again. Is it because some cells have data validation on it? And
they're data input is restricted?
Or is there another way of making this work?
Help. :)





  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 84
Default Workbook_BeforeClose Question

Sashi wrote:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

....
These lines are in Sheet1. What else can I do?



As Dave Thomas wrote, the code must be in the "ThisWorkbook" module. The
rule is determined by the name of of the subroutine. You have a
Workbook_ and not a Worksheet_ subroutine.

- David
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Workbook_BeforeClose Question

Before_Close code must be entered into ThisWorkbook module.

Entering in a sheet module won't run it.


Gord

On Thu, 26 Jul 2007 11:44:11 -0700, Sashi
wrote:

Hi Gord,

I'm so sorry for being such a pain, but I tried your suggestion, leme show
you my whole code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
'ThisWorkbook.Save *I actually tried both*
ActiveWorkbook.Save
End Sub

These lines are in Sheet1. What else can I do?


"Gord Dibben" wrote:

You cannot save a worksheet. You must save the workbook

Thisworkbook.save

or

ActiveWorkbook.save


Gord Dibben MS Excel MVP

On Wed, 25 Jul 2007 08:04:01 -0700, Sashi
wrote:

Hi Dave,

My code is already in ThisWorkbook, so it shouldn't be a problem. :(
Hello Jim,

I already added the line:

Worksheets("Sheet1").Save

after clearing the contents, it still didn't work. :(

Sashi

"Jim Cone" wrote:


You need to save the workbook after clearing the cells.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Sashi"
wrote in message
I'm using this code to clear everything within the range of C14 to C21
(Sheet1) before my workbook closes:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("C14:C21").ClearContent s
End Sub

I wonder why it doesn't work. The data still remain (in the cells) if I
open it again. Is it because some cells have data validation on it? And
they're data input is restricted?
Or is there another way of making this work?
Help. :)






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Question metaltecks Excel Discussion (Misc queries) 2 March 29th 06 08:48 PM
The question is an excel question that I need to figure out howto do in excel. Terry Excel Worksheet Functions 3 January 23rd 06 06:22 PM
If Question carl Excel Worksheet Functions 2 December 29th 04 06:01 PM
IF Question carl Excel Worksheet Functions 2 December 29th 04 04:08 PM


All times are GMT +1. The time now is 10:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"