View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alerion Alerion is offline
external usenet poster
 
Posts: 11
Default Excel 2003 SP2 fires events without reason when saving workboo

Yes, it has all those elements you stated, and in that partiucular order
aswell. I don't yet have skinned the code. I will do it tomorrow and send it.

I have also managed to get excel vba to write to random cells on a protected
worksheet without asking it to do so, but that's beside the point in this
matter. :D

Till tomorrow,

Alerion


"Jim Rech" kirjoitti:

Is your real SaveClick code like this?:

Private sub SaveBtn_Click
Application.EnableEvents = False
EventsEnabled = False
thisworkbook.saveas myfilename

Application.EnableEvents = True
EventsEnabled = True
End sub

If so I cannot imagine what is setting back the cell values. I don't
suppose you have a slimmed down version that does this that you can send me?

--
Jim
"Alerion" wrote in message
...
| Thank you for you idea. This is one workaround that I have used. And it
| worked pretty well: The code in combobox_change was not executed.
|
| However, one of my problems didn't end there, and that is a problem that I
| am really confused about. I will try to explain what my code does in
words.
| Right now I'm skinning the code to simple basics and trying to pinpoint
the
| cause.
|
| Last one of these comboboxes has a list of product names. When selected,
it
| writes the combobox value to a cell. Then (with some criteria) it fetches
the
| product code from a list in another worksheet and writes that to another
cell.
|
| I also have a checkbox that changes the language of the product name,
| Finnish to English and vice versa. It looks for the product code in this
| aforementioned list and when found, it swithches the product name in the
| aforementioned cell to the other language. So far so good. And now we get
to
| interesting events.
|
| After this is done, I click a button that saves the workbook.
|
| Simplified code:
| Private sub btn_save.click
| thisworkbook.saveas (myfilename)
| end sub
|
| Private sub cbo1Prod.change
| if EnableEvents = true then
| code code code
| End if
| End sub
|
| I have combed through the code with F8. After the saveas statement, the
| change event is fired. It does not execute the code in the change event at
| all. But when the "Private sub cbo1Prod.change" line is highlighted with
| yellow, the product name in the cell has turned back to the original
language.
|
| This is very strange. The checkbox code was not run, neither the code in
the
| change event.
|
| Any ideas? :)
|
| Alerion
|
|
| It does not execute the code
| "Jim Rech" kirjoitti:
|
| The events of userforms or Control Toolbar controls on worksheets are
not
| controlled by Application.EnableEvents. For these items you have to
| establish your own enable events mechanism. For instance, you could
have a
| public variable like:
|
| Public EventsEnabled As Boolean
|
| in the standard module of your choice. And then for each control you
could
| refer to it:
|
| Private Sub ListBox1_Click()
| If EventsEnabled Then
| ''Run my code
| End If
| End Sub
|
| You would set EventsEnabled to True in normal user use and False before
a
| save or any other time you do not want control event code to run.
|
| --
| Jim
|