Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Events problem

I have a single sheet workbook open, with Event code
in the ThisWorkbook module. No other modules.

User makes changes to permitted fields in the sheet
and then attempts to Save. Code runs which creates
a new book, copies the sheet to it (thus not copying
the Thisworkbook code), saves the book with the user's
new name, and leaves it open.

I now remove most of the user's changes to the original
Worksheet (the original book still being open) and then
attempt to close the original using this code:

With Workbooks(wkbkname).Worksheets("Master Order")
.Unprotect Password:= "abc"
.Range("H11").ClearContents
.Range("A2:E15").ClearContents
.Range("A31:K46").ClearContents
.Range("A50:K53").ClearContents
.Range("A57:K63").ClearContents
.Protect Password:= "abc"
End With
Application.EnableEvents = True 'Line1
Workbooks(wkbkname).Close SaveChanges:=True
Application.ScreenUpdating = True
End If
Application.EnableEvents = True
End Sub

When the Close code line runs, the code jumps to the
Before_Close routine which says:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
Application.EnableEvents = True
End Sub

and the changes are not saved.

If I change the line marked as 'Line1 to
Application.EnableEvents = False
the the changes will stick, but Events are turned off.

What can I do, please?

Regards.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Events problem

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
Application.EnableEvents = True
End Sub

Just get rid of this code. The first line tells Excel there are no changes
so the Workbook.close doesn't save. The second line is superfluous since
events have to be enabled for this code to be called in the first place.

--
Jim Rech
Excel MVP
"Stuart" wrote in message
...
|I have a single sheet workbook open, with Event code
| in the ThisWorkbook module. No other modules.
|
| User makes changes to permitted fields in the sheet
| and then attempts to Save. Code runs which creates
| a new book, copies the sheet to it (thus not copying
| the Thisworkbook code), saves the book with the user's
| new name, and leaves it open.
|
| I now remove most of the user's changes to the original
| Worksheet (the original book still being open) and then
| attempt to close the original using this code:
|
| With Workbooks(wkbkname).Worksheets("Master Order")
| .Unprotect Password:= "abc"
| .Range("H11").ClearContents
| .Range("A2:E15").ClearContents
| .Range("A31:K46").ClearContents
| .Range("A50:K53").ClearContents
| .Range("A57:K63").ClearContents
| .Protect Password:= "abc"
| End With
| Application.EnableEvents = True 'Line1
| Workbooks(wkbkname).Close SaveChanges:=True
| Application.ScreenUpdating = True
| End If
| Application.EnableEvents = True
| End Sub
|
| When the Close code line runs, the code jumps to the
| Before_Close routine which says:
|
| Private Sub Workbook_BeforeClose(Cancel As Boolean)
| ThisWorkbook.Saved = True
| Application.EnableEvents = True
| End Sub
|
| and the changes are not saved.
|
| If I change the line marked as 'Line1 to
| Application.EnableEvents = False
| the the changes will stick, but Events are turned off.
|
| What can I do, please?
|
| Regards.
|
|
| ---
| Outgoing mail is certified Virus Free.
| Checked by AVG anti-virus system (http://www.grisoft.com).
| Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Events problem

Many thanks.

The Before_Close Event code was an attempt to allow
the user to click the little 'x' (top right) and Cancel.
By that I mean that if part way through and having
made some changes, they decided to Cancel, then
the workbook would close without any changes being
saved.

What is the correct way to cater for that eventuality,
please?

Regards.

"Jim Rech" wrote in message
...
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
Application.EnableEvents = True
End Sub

Just get rid of this code. The first line tells Excel there are no

changes
so the Workbook.close doesn't save. The second line is superfluous since
events have to be enabled for this code to be called in the first place.

--
Jim Rech
Excel MVP
"Stuart" wrote in message
...
|I have a single sheet workbook open, with Event code
| in the ThisWorkbook module. No other modules.
|
| User makes changes to permitted fields in the sheet
| and then attempts to Save. Code runs which creates
| a new book, copies the sheet to it (thus not copying
| the Thisworkbook code), saves the book with the user's
| new name, and leaves it open.
|
| I now remove most of the user's changes to the original
| Worksheet (the original book still being open) and then
| attempt to close the original using this code:
|
| With Workbooks(wkbkname).Worksheets("Master Order")
| .Unprotect Password:= "abc"
| .Range("H11").ClearContents
| .Range("A2:E15").ClearContents
| .Range("A31:K46").ClearContents
| .Range("A50:K53").ClearContents
| .Range("A57:K63").ClearContents
| .Protect Password:= "abc"
| End With
| Application.EnableEvents = True 'Line1
| Workbooks(wkbkname).Close SaveChanges:=True
| Application.ScreenUpdating = True
| End If
| Application.EnableEvents = True
| End Sub
|
| When the Close code line runs, the code jumps to the
| Before_Close routine which says:
|
| Private Sub Workbook_BeforeClose(Cancel As Boolean)
| ThisWorkbook.Saved = True
| Application.EnableEvents = True
| End Sub
|
| and the changes are not saved.
|
| If I change the line marked as 'Line1 to
| Application.EnableEvents = False
| the the changes will stick, but Events are turned off.
|
| What can I do, please?
|
| Regards.
|
|
| ---
| Outgoing mail is certified Virus Free.
| Checked by AVG anti-virus system (http://www.grisoft.com).
| Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
|
|




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Events problem

In the main save routine I'd check the .Saved property and if it's false I'd
ask the user to save changes with my own msgbox. If yes I'd do the copy to
and save of the data workbook. If no I'd just close. In any case I'm not
clear on why you are clearing all those cells in the master. If you just
close with 'save changes:=false' wouldn't you be in the same place as when
you started? (Presumably with a "clear" workbook?

--
Jim Rech
Excel MVP
"Stuart" wrote in message
...
| Many thanks.
|
| The Before_Close Event code was an attempt to allow
| the user to click the little 'x' (top right) and Cancel.
| By that I mean that if part way through and having
| made some changes, they decided to Cancel, then
| the workbook would close without any changes being
| saved.
|
| What is the correct way to cater for that eventuality,
| please?
|
| Regards.
|
| "Jim Rech" wrote in message
| ...
| Private Sub Workbook_BeforeClose(Cancel As Boolean)
| ThisWorkbook.Saved = True
| Application.EnableEvents = True
| End Sub
|
| Just get rid of this code. The first line tells Excel there are no
| changes
| so the Workbook.close doesn't save. The second line is superfluous
since
| events have to be enabled for this code to be called in the first place.
|
| --
| Jim Rech
| Excel MVP
| "Stuart" wrote in message
| ...
| |I have a single sheet workbook open, with Event code
| | in the ThisWorkbook module. No other modules.
| |
| | User makes changes to permitted fields in the sheet
| | and then attempts to Save. Code runs which creates
| | a new book, copies the sheet to it (thus not copying
| | the Thisworkbook code), saves the book with the user's
| | new name, and leaves it open.
| |
| | I now remove most of the user's changes to the original
| | Worksheet (the original book still being open) and then
| | attempt to close the original using this code:
| |
| | With Workbooks(wkbkname).Worksheets("Master Order")
| | .Unprotect Password:= "abc"
| | .Range("H11").ClearContents
| | .Range("A2:E15").ClearContents
| | .Range("A31:K46").ClearContents
| | .Range("A50:K53").ClearContents
| | .Range("A57:K63").ClearContents
| | .Protect Password:= "abc"
| | End With
| | Application.EnableEvents = True 'Line1
| | Workbooks(wkbkname).Close SaveChanges:=True
| | Application.ScreenUpdating = True
| | End If
| | Application.EnableEvents = True
| | End Sub
| |
| | When the Close code line runs, the code jumps to the
| | Before_Close routine which says:
| |
| | Private Sub Workbook_BeforeClose(Cancel As Boolean)
| | ThisWorkbook.Saved = True
| | Application.EnableEvents = True
| | End Sub
| |
| | and the changes are not saved.
| |
| | If I change the line marked as 'Line1 to
| | Application.EnableEvents = False
| | the the changes will stick, but Events are turned off.
| |
| | What can I do, please?
| |
| | Regards.
| |
| |
| | ---
| | Outgoing mail is certified Virus Free.
| | Checked by AVG anti-virus system (http://www.grisoft.com).
| | Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
| |
| |
|
|
|
|
| ---
| Outgoing mail is certified Virus Free.
| Checked by AVG anti-virus system (http://www.grisoft.com).
| Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
|
|


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Events problem

Thanks for that. I'll work with your suggestions.

Why clear certain cells and then save as True? Well,
one cell contains an order number, and this needs to
increment.
So by the time this code is reached, user has committed
a save, the new workbook has been created and saved
(and it is open and stripped of code).
With the original workbook, I now remove all the user's
new entries and force save changes as true, such that
the new order number is preserved.

If user next opens the original file, then the order
number is incremented in the Workbook_Open Event

Background: I'm tasked with standardising Company
documents eg: Orders, Fax, etc.
I've users who are "uncooperative"....they prefer their
own creativity! Nevertheless it will happen.

With this early code I'm trying to show the advantages
to the user (eg automatic insertion of the current date,
saving standard data.....saves typing it every time etc).

When they're on my side (hopefuuly soon) then I'm
thinking an addin will be the best route.

BTW I'm with XL2000 and they have 2003.
At the moment they face the macro warning message
when code runs. If I develop the addin under 2000
as opposed to 2003, would there be issues viz-a
viz Certification?

Many thanks for your help.

Regards

"Jim Rech" wrote in message
...
In the main save routine I'd check the .Saved property and if it's false

I'd
ask the user to save changes with my own msgbox. If yes I'd do the copy

to
and save of the data workbook. If no I'd just close. In any case I'm not
clear on why you are clearing all those cells in the master. If you just
close with 'save changes:=false' wouldn't you be in the same place as when
you started? (Presumably with a "clear" workbook?

--
Jim Rech
Excel MVP
"Stuart" wrote in message
...
| Many thanks.
|
| The Before_Close Event code was an attempt to allow
| the user to click the little 'x' (top right) and Cancel.
| By that I mean that if part way through and having
| made some changes, they decided to Cancel, then
| the workbook would close without any changes being
| saved.
|
| What is the correct way to cater for that eventuality,
| please?
|
| Regards.
|
| "Jim Rech" wrote in message
| ...
| Private Sub Workbook_BeforeClose(Cancel As Boolean)
| ThisWorkbook.Saved = True
| Application.EnableEvents = True
| End Sub
|
| Just get rid of this code. The first line tells Excel there are no
| changes
| so the Workbook.close doesn't save. The second line is superfluous
since
| events have to be enabled for this code to be called in the first

place.
|
| --
| Jim Rech
| Excel MVP
| "Stuart" wrote in message
| ...
| |I have a single sheet workbook open, with Event code
| | in the ThisWorkbook module. No other modules.
| |
| | User makes changes to permitted fields in the sheet
| | and then attempts to Save. Code runs which creates
| | a new book, copies the sheet to it (thus not copying
| | the Thisworkbook code), saves the book with the user's
| | new name, and leaves it open.
| |
| | I now remove most of the user's changes to the original
| | Worksheet (the original book still being open) and then
| | attempt to close the original using this code:
| |
| | With Workbooks(wkbkname).Worksheets("Master Order")
| | .Unprotect Password:= "abc"
| | .Range("H11").ClearContents
| | .Range("A2:E15").ClearContents
| | .Range("A31:K46").ClearContents
| | .Range("A50:K53").ClearContents
| | .Range("A57:K63").ClearContents
| | .Protect Password:= "abc"
| | End With
| | Application.EnableEvents = True 'Line1
| | Workbooks(wkbkname).Close SaveChanges:=True
| | Application.ScreenUpdating = True
| | End If
| | Application.EnableEvents = True
| | End Sub
| |
| | When the Close code line runs, the code jumps to the
| | Before_Close routine which says:
| |
| | Private Sub Workbook_BeforeClose(Cancel As Boolean)
| | ThisWorkbook.Saved = True
| | Application.EnableEvents = True
| | End Sub
| |
| | and the changes are not saved.
| |
| | If I change the line marked as 'Line1 to
| | Application.EnableEvents = False
| | the the changes will stick, but Events are turned off.
| |
| | What can I do, please?
| |
| | Regards.
| |
| |
| | ---
| | Outgoing mail is certified Virus Free.
| | Checked by AVG anti-virus system (http://www.grisoft.com).
| | Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
| |
| |
|
|
|
|
| ---
| Outgoing mail is certified Virus Free.
| Checked by AVG anti-virus system (http://www.grisoft.com).
| Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
|
|




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Events problem

If I develop the addin under 2000 as opposed to 2003, would there be
issues viz-a viz Certification?


Probably not but I'm not sure.

Too bad you can't have an external "next number" so the workbook doesn't
have to be saved. Like saved in its own little Excel file. Hmm...


--
Jim Rech
Excel MVP
"Stuart" wrote in message
...
| Thanks for that. I'll work with your suggestions.
|
| Why clear certain cells and then save as True? Well,
| one cell contains an order number, and this needs to
| increment.
| So by the time this code is reached, user has committed
| a save, the new workbook has been created and saved
| (and it is open and stripped of code).
| With the original workbook, I now remove all the user's
| new entries and force save changes as true, such that
| the new order number is preserved.
|
| If user next opens the original file, then the order
| number is incremented in the Workbook_Open Event
|
| Background: I'm tasked with standardising Company
| documents eg: Orders, Fax, etc.
| I've users who are "uncooperative"....they prefer their
| own creativity! Nevertheless it will happen.
|
| With this early code I'm trying to show the advantages
| to the user (eg automatic insertion of the current date,
| saving standard data.....saves typing it every time etc).
|
| When they're on my side (hopefuuly soon) then I'm
| thinking an addin will be the best route.
|
| BTW I'm with XL2000 and they have 2003.
| At the moment they face the macro warning message
| when code runs. If I develop the addin under 2000
| as opposed to 2003, would there be issues viz-a
| viz Certification?
|
| Many thanks for your help.
|
| Regards
|
| "Jim Rech" wrote in message
| ...
| In the main save routine I'd check the .Saved property and if it's false
| I'd
| ask the user to save changes with my own msgbox. If yes I'd do the copy
| to
| and save of the data workbook. If no I'd just close. In any case I'm
not
| clear on why you are clearing all those cells in the master. If you
just
| close with 'save changes:=false' wouldn't you be in the same place as
when
| you started? (Presumably with a "clear" workbook?
|
| --
| Jim Rech
| Excel MVP
| "Stuart" wrote in message
| ...
| | Many thanks.
| |
| | The Before_Close Event code was an attempt to allow
| | the user to click the little 'x' (top right) and Cancel.
| | By that I mean that if part way through and having
| | made some changes, they decided to Cancel, then
| | the workbook would close without any changes being
| | saved.
| |
| | What is the correct way to cater for that eventuality,
| | please?
| |
| | Regards.
| |
| | "Jim Rech" wrote in message
| | ...
| | Private Sub Workbook_BeforeClose(Cancel As Boolean)
| | ThisWorkbook.Saved = True
| | Application.EnableEvents = True
| | End Sub
| |
| | Just get rid of this code. The first line tells Excel there are no
| | changes
| | so the Workbook.close doesn't save. The second line is superfluous
| since
| | events have to be enabled for this code to be called in the first
| place.
| |
| | --
| | Jim Rech
| | Excel MVP
| | "Stuart" wrote in message
| | ...
| | |I have a single sheet workbook open, with Event code
| | | in the ThisWorkbook module. No other modules.
| | |
| | | User makes changes to permitted fields in the sheet
| | | and then attempts to Save. Code runs which creates
| | | a new book, copies the sheet to it (thus not copying
| | | the Thisworkbook code), saves the book with the user's
| | | new name, and leaves it open.
| | |
| | | I now remove most of the user's changes to the original
| | | Worksheet (the original book still being open) and then
| | | attempt to close the original using this code:
| | |
| | | With Workbooks(wkbkname).Worksheets("Master Order")
| | | .Unprotect Password:= "abc"
| | | .Range("H11").ClearContents
| | | .Range("A2:E15").ClearContents
| | | .Range("A31:K46").ClearContents
| | | .Range("A50:K53").ClearContents
| | | .Range("A57:K63").ClearContents
| | | .Protect Password:= "abc"
| | | End With
| | | Application.EnableEvents = True 'Line1
| | | Workbooks(wkbkname).Close SaveChanges:=True
| | | Application.ScreenUpdating = True
| | | End If
| | | Application.EnableEvents = True
| | | End Sub
| | |
| | | When the Close code line runs, the code jumps to the
| | | Before_Close routine which says:
| | |
| | | Private Sub Workbook_BeforeClose(Cancel As Boolean)
| | | ThisWorkbook.Saved = True
| | | Application.EnableEvents = True
| | | End Sub
| | |
| | | and the changes are not saved.
| | |
| | | If I change the line marked as 'Line1 to
| | | Application.EnableEvents = False
| | | the the changes will stick, but Events are turned off.
| | |
| | | What can I do, please?
| | |
| | | Regards.
| | |
| | |
| | | ---
| | | Outgoing mail is certified Virus Free.
| | | Checked by AVG anti-virus system (http://www.grisoft.com).
| | | Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
| | |
| | |
| |
| |
| |
| |
| | ---
| | Outgoing mail is certified Virus Free.
| | Checked by AVG anti-virus system (http://www.grisoft.com).
| | Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
| |
| |
|
|
|
|
| ---
| Outgoing mail is certified Virus Free.
| Checked by AVG anti-virus system (http://www.grisoft.com).
| Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
|
|


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Events problem

Too bad you can't have an external "next number" so the workbook doesn't
have to be saved. Like saved in its own little Excel file. Hmm...


Not too sure what you're suggesting/considering there, but what about this:

1. User navigates to a shared network drive and copies a 'Master Order'
workbook (single worksheet) to their local folder. The Order No in the
Master and copy is '1000'. Neither the Master nor the copy can be
edited by the user at this stage, except to force the user to change the
filename, and select their folder for the copy.
(I have code for this).
2. They open the copy, and code in the WorkBook_Open Event in the
ThisWorkbook module tests the value of the Order no. If '1000' then
it must be a copy of the Master
They are then directed to fill every cell that will contain common data
for every Order they wll raise for that Project (kind of like creating a
Master Order for that Project). They cannot edit any other cells. They
are then forced to save the Contract Master Order with a new name,
and to a folder of their choice.
( I have code for this).
3. They then open the Contract Master Order for the first time. Code in
ThisWorkbook tests if it's a Master Order or Contract Master wkbk.
If Contract Master, then the Order no is increased by one.
(I have code for this)

Let's assume that a Contract Master Order has been opened for the first
time......

The Order no will be '1001'
When initially opened, the sheet will display the standard info for that
Contract (eg delivery address etc ... whatever user chose earlier).
User will now be able to fill in other fields, and when they Save, will
be forced to choose a new filename, and select the Save folder.
(I have code to do this).
.....to achieve this, I add a new book, copy the single sheet in the
Contract Master & paste into the new book, delete empty sheets
in the new book.

I now have the Contract Master book open, and the new book
active (and where the new book contains no code).

As best I can tell, here's the requirements:

If user elects to save the new book Then
save the book 'completely protected ... no editing
save the Contract Master book and
i) preserve the new Order no
ii) remove any other changes to Contract Master
iii) completely protect the workbook

So what of this suggestion:

If a test found that the Contract Master Order was being opened
for the first time ( ie Order no = '1000') then create a new book.
Allow code to increment the Order no, and store that in the new
book say "Order no.xls"
Later, Contract Master Order could be closed with no changes,
but when re-opened, a new test would look for the book
"Order no" and update the Order no.

Can a link be achieved, and is this achievable/ a sensible approach?
Obviously there will be many Contract Master Orders and
therefore corresponding "Order no" books. They would need
to be irrevocorably linked?

Many thanks for your help.

Regards.

Jim Rech" wrote in message

...
If I develop the addin under 2000 as opposed to 2003, would there be
issues viz-a viz Certification?


Probably not but I'm not sure.

Too bad you can't have an external "next number" so the workbook doesn't
have to be saved. Like saved in its own little Excel file. Hmm...


--
Jim Rech
Excel MVP
"Stuart" wrote in message
...
| Thanks for that. I'll work with your suggestions.
|
| Why clear certain cells and then save as True? Well,
| one cell contains an order number, and this needs to
| increment.
| So by the time this code is reached, user has committed
| a save, the new workbook has been created and saved
| (and it is open and stripped of code).
| With the original workbook, I now remove all the user's
| new entries and force save changes as true, such that
| the new order number is preserved.
|
| If user next opens the original file, then the order
| number is incremented in the Workbook_Open Event
|
| Background: I'm tasked with standardising Company
| documents eg: Orders, Fax, etc.
| I've users who are "uncooperative"....they prefer their
| own creativity! Nevertheless it will happen.
|
| With this early code I'm trying to show the advantages
| to the user (eg automatic insertion of the current date,
| saving standard data.....saves typing it every time etc).
|
| When they're on my side (hopefuuly soon) then I'm
| thinking an addin will be the best route.
|
| BTW I'm with XL2000 and they have 2003.
| At the moment they face the macro warning message
| when code runs. If I develop the addin under 2000
| as opposed to 2003, would there be issues viz-a
| viz Certification?
|
| Many thanks for your help.
|
| Regards
|
| "Jim Rech" wrote in message
| ...
| In the main save routine I'd check the .Saved property and if it's

false
| I'd
| ask the user to save changes with my own msgbox. If yes I'd do the

copy
| to
| and save of the data workbook. If no I'd just close. In any case I'm
not
| clear on why you are clearing all those cells in the master. If you
just
| close with 'save changes:=false' wouldn't you be in the same place as
when
| you started? (Presumably with a "clear" workbook?
|
| --
| Jim Rech
| Excel MVP
| "Stuart" wrote in message
| ...
| | Many thanks.
| |
| | The Before_Close Event code was an attempt to allow
| | the user to click the little 'x' (top right) and Cancel.
| | By that I mean that if part way through and having
| | made some changes, they decided to Cancel, then
| | the workbook would close without any changes being
| | saved.
| |
| | What is the correct way to cater for that eventuality,
| | please?
| |
| | Regards.
| |
| | "Jim Rech" wrote in message
| | ...
| | Private Sub Workbook_BeforeClose(Cancel As Boolean)
| | ThisWorkbook.Saved = True
| | Application.EnableEvents = True
| | End Sub
| |
| | Just get rid of this code. The first line tells Excel there are

no
| | changes
| | so the Workbook.close doesn't save. The second line is

superfluous
| since
| | events have to be enabled for this code to be called in the first
| place.
| |
| | --
| | Jim Rech
| | Excel MVP
| | "Stuart" wrote in message
| | ...
| | |I have a single sheet workbook open, with Event code
| | | in the ThisWorkbook module. No other modules.
| | |
| | | User makes changes to permitted fields in the sheet
| | | and then attempts to Save. Code runs which creates
| | | a new book, copies the sheet to it (thus not copying
| | | the Thisworkbook code), saves the book with the user's
| | | new name, and leaves it open.
| | |
| | | I now remove most of the user's changes to the original
| | | Worksheet (the original book still being open) and then
| | | attempt to close the original using this code:
| | |
| | | With Workbooks(wkbkname).Worksheets("Master Order")
| | | .Unprotect Password:= "abc"
| | | .Range("H11").ClearContents
| | | .Range("A2:E15").ClearContents
| | | .Range("A31:K46").ClearContents
| | | .Range("A50:K53").ClearContents
| | | .Range("A57:K63").ClearContents
| | | .Protect Password:= "abc"
| | | End With
| | | Application.EnableEvents = True 'Line1
| | | Workbooks(wkbkname).Close SaveChanges:=True
| | | Application.ScreenUpdating = True
| | | End If
| | | Application.EnableEvents = True
| | | End Sub
| | |
| | | When the Close code line runs, the code jumps to the
| | | Before_Close routine which says:
| | |
| | | Private Sub Workbook_BeforeClose(Cancel As Boolean)
| | | ThisWorkbook.Saved = True
| | | Application.EnableEvents = True
| | | End Sub
| | |
| | | and the changes are not saved.
| | |
| | | If I change the line marked as 'Line1 to
| | | Application.EnableEvents = False
| | | the the changes will stick, but Events are turned off.
| | |
| | | What can I do, please?
| | |
| | | Regards.
| | |
| | |
| | | ---
| | | Outgoing mail is certified Virus Free.
| | | Checked by AVG anti-virus system (http://www.grisoft.com).
| | | Version: 6.0.714 / Virus Database: 470 - Release Date:

02/07/2004
| | |
| | |
| |
| |
| |
| |
| | ---
| | Outgoing mail is certified Virus Free.
| | Checked by AVG anti-virus system (http://www.grisoft.com).
| | Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
| |
| |
|
|
|
|
| ---
| Outgoing mail is certified Virus Free.
| Checked by AVG anti-virus system (http://www.grisoft.com).
| Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004
|
|




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.716 / Virus Database: 472 - Release Date: 05/07/2004


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
Events won't Disable! roadkill Excel Discussion (Misc queries) 2 April 26th 06 04:36 PM
events? [email protected] Excel Discussion (Misc queries) 1 September 14th 05 03:26 PM
events Mark[_17_] Excel Programming 1 October 31st 03 09:18 AM
events Mark[_17_] Excel Programming 1 October 29th 03 12:56 PM
Events on shapes Christof De Backere Excel Programming 1 September 2nd 03 03:35 PM


All times are GMT +1. The time now is 06:06 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"