View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Stop Macros from Running When Workbook Opened via Automation

Are you sure you properly qualified EnableEvents as Dave showed?

Don't worry about Auto_Open, it is far too widespread for MS to remove it.
It will probably disappear in a version where backward compatibility is
completely lost.

--
HTH

Bob Phillips

"Google Boy of Company C"
wrote in message ...
Hi Dave

I have found time to do some further testing on this. Using EnableEvents =
False does not stop the code from running, whereas using Auto_Open()

instead
of Workbook_Open() solves my problem.

From further reading it would seem that Auto_Open() originates from older
versions of Excel and has only been left in for compatability. Should
Microsoft remove it in future I might be stuffed.

Kind regards
Tim ffitch

"Dave Peterson" wrote:

You're opening an instance of excel and opening your workbook?

Maybe something like:

Dim XLApp As Object
Dim XLWkbk As Object

Set XLApp = CreateObject("Excel.Application")

xlapp.visible = true 'nice for testing
xlapp.enableevents = false 'stop workbook_open event

set xlwkbk = xlapp.workbooks.open("c:\myfolder1\myfolder2\test. xls")

'do your work

xlwkbk.close savechanges:=false

xlapp.enableevents = true

set xlwkbk = nothing
xlapp.quit
set xlapp = nothing


Google Boy of Company C wrote:

"MyFileI have an excel workbook that when opened by the user runs a

macro
from the Workbook.OnOpen event. This then displays a VB form for the

user to
enter some data.

I need to open this workbook using VBA from Access, add some data into

the
cells on Sheet1, save and close the workbook and then email it to the

user.

The problem is that when I use WorkBooks.Open("MyFileName") the code

in the
Workbook.OnOpen event takes over and displays the form.

Is there any way I can stop all code in the workbook from running when

I
open it using WorkBooks.Open("MyFileName"). The Macro security feature

does
not apply in this case as this method seems to ignore the setting

anyway.

Please help as I have reached a dead end.
Kind regards
Tim


--

Dave Peterson