View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
MWE[_28_] MWE[_28_] is offline
external usenet poster
 
Posts: 1
Default Disabling Events

I have a VBA procedure that runs in Outlook. It opens an Excel
spreadsheet (A.xls), reads some data from sheet "B" and then closes
A.xls There are macros in A.xls and in my Personal.xls that will
execute on open. I do not want that to happen when A.xls is opened
from Outlook. I have tried using the EventsEnable = False (which works
when one spreadsheet is opening another), but that does not seem to
work here. The problem is not the macros in A.xls but the macros in
Personal.xls. One of those macros does a lot of fetching from yet
other spreadsheets, build menus, and other stuff. If that macro
executes, it seems to get confused and generate a compiler error. The
Outlook procedure still runs correctly to completion but I would like
to eliminate the error. Any help would be appreciated. The relevant
VBA code (in Outlook) is below.

Thanks


'
' define Excel types
'
Dim xLApp As Excel.Application
Dim xLBook As Excel.Workbook
Dim xLSheet As Excel.Worksheet
'
' traditional definitions
'
Dim xLPath As String
Dim xLFileName As String
'
' define location and filename of target spreadsheet
'
xLPath = "D:\TestArea"
xLFileName = "A.xls"
'
' define application object
' set events to false (so macros do not run on startup)
'
Set xLApp = CreateObject("Excel.Application")
xLApp.EnableEvents = False
'
' open target spreadsheet
' define target worksheet
'
xLApp.Workbooks.Open FileName:=xLPath + "\" + xLFileName
Set xLSheet = xLApp.Workbooks(xLFileName).Worksheets("B")
'
' perform spreadsheet operations
'
... do various things ...

'
' close spreadsheet
' misc housekeeping
'
xLApp.Workbooks(xLFileName).Close


---
Message posted from http://www.ExcelForum.com/