Application.EnableEvents not working on a second workbook

nyconfidential

New Member
Joined
Jul 22, 2015
Messages
49
Office Version
  1. 365
  2. 2016
Hi All - I wrote a sub that copies certain formulas from one workbook to another blank workbook. I've set Application.EnableEvents to false - this seems to work fine if I'm copying code to another sheet in the same workbook, but if I'm copying to another workbook, events are triggered and I receive an error. I assumed that when something is done on the Application level it would turn off events for every workbook that is open, am I incorrect? Is there something else I need to do turn off events for the second workbook? Thanks in advance.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Your reasoning seems sound. I suspect you are opening another instance of the Excel application? I don't know without seeing the code
 
Upvote 0
Your reasoning seems sound. I suspect you are opening another instance of the Excel application? I don't know without seeing the code

Here ya go Roderick - the Worksheet_change event in the workbook that is getting updated(ActiveWorkbook) is triggered even though Application.EnableEvents is set to false. (And yes, two instances of Excel are open) Thanks!

Code:
Public Sub ReplaceformulasUsedRange()


Dim rCell As Range
Dim rRng As Object
Dim WrkSht As Worksheet


Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False


For Each WrkSht In ThisWorkbook.Worksheets
    If SheetExists(WrkSht.Name) Then
    ActiveWorkbook.Sheets(WrkSht.Name).UsedRange.Formula =ThisWorkbook.Sheets(WrkSht.Name).UsedRange.Formula
End If
'Debug.Print WrkSht.Name
Next WrkSht


Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
MsgBox "Updated"
End Sub
 
Last edited:
Upvote 0
Thanks. You said this is triggering or triggered by Worksheet_Change? If so, EnableEvents keeps getting turned back to True in this code. How/when is Worksheet_Change involved?
 
Upvote 0
When this line of code is executed:

Code:
[COLOR=#333333]    ActiveWorkbook.Sheets(WrkSht.Name).UsedRange.Formula =ThisWorkbook.Sheets(WrkSht.Name).UsedRange.Formula

[/COLOR]The Worksheet_change event on the workbook that is getting updated(copied to) is triggered. I'm setting enableevents to false in the OTHER workbook, the one I am copying data from.
 
Upvote 0
I'm thinking you should turn off the events in the Worksheet_Change event as well. Humor me :-)
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top