Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Make a file save and close itself based on the value of a cell

If Sheet1!A1's value is = 1, then I would like for the file to save
and then close itself. Is this possible? Thanks in advance.

Michael
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Make a file save and close itself based on the value of a cell

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

If Target.Value = 1 Then

Parent.Save
Parent.Close
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--

HTH

Bob

"Michael Lanier" wrote in message
...
If Sheet1!A1's value is = 1, then I would like for the file to save
and then close itself. Is this possible? Thanks in advance.

Michael



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Make a file save and close itself based on the value of a cell

Bob,

Thanks for your help. I'm at a bit of a loss. I placed your macro in
a new file. I then assigned the file a name and saved it. When I
triggered the event by enter the number 1 in A1 and it saved the file
as intended. When I reopened it and made a minor change and then
reentered the 1 value in A1, nothing happened. Do you have any
further ideas? Thanks.

Michael
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Make a file save and close itself based on the value of a cell

Hi Michael, the way the macro is set up, it will close without enabling
events again, so when you re-open the file the events are disabled. There
are a couple of ways to get around this. Below is my suggestion:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A2" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

If Target.Value = 1 Then

Parent.Save
Application.EnableEvents = True '<<<add this line
Parent.Close
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub


"Michael Lanier" wrote in message
...
Bob,

Thanks for your help. I'm at a bit of a loss. I placed your macro in
a new file. I then assigned the file a name and saved it. When I
triggered the event by enter the number 1 in A1 and it saved the file
as intended. When I reopened it and made a minor change and then
reentered the 1 value in A1, nothing happened. Do you have any
further ideas? Thanks.

Michael



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Make a file save and close itself based on the value of a cell

Thanks for your help. I'll be giving it a try shortly.

Michael


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
Save 1 file to different folders based on cell.value Gaba Excel Programming 2 February 27th 09 01:38 PM
SAVE & SEND A FILE BASED ON TEXT IN A CELL VIA MACRO Pat Baratta New Users to Excel 1 February 26th 07 06:46 AM
Close & save a file at set time only IF the file is open Clivey_UK[_5_] Excel Programming 2 May 1st 06 06:19 PM
Automatically save file based on cell value Craig Excel Discussion (Misc queries) 0 February 27th 05 10:01 PM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


All times are GMT +1. The time now is 07:17 AM.

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

About Us

"It's about Microsoft Excel"