Link to home
Start Free TrialLog in
Avatar of MJDercks
MJDercksFlag for United States of America

asked on

Application vs Workbook.applicaiton

If I have two WBs open  can I use WB1.Application.EnableEvents to set this for one but not the other?  In general why would one use WB.Application as opposed to just Application.  By the way,  I am using 2013
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the other Excel instance is opened as a new application within the code, then it is possible to get access to it from the code.

See below example where events are turned off in the new application, but remains active in the first application with the code.

Option Explicit
Public xApp As Excel.Application

Sub OpenWorkbookInNewApplication()
    Dim fName As String
    fName = Application.GetOpenFilename("Excel files, *.xls*")
    
    Set xApp = New Excel.Application
    xApp.Visible = True
    xApp.EnableEvents = False
    xApp.Workbooks.Open Filename:=fName
End Sub

Sub WriteToSheetInNewApplication()
    xApp.ActiveSheet.Range("A1") = "Text"
End Sub

Sub CloseNewApplication()
    xApp.ActiveWorkbook.Close True
    xApp.Quit
End Sub

Open in new window

Avatar of MJDercks

ASKER

Thanks All