Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Stop Macros from Running When Workbook Opened via Automation

"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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Stop Macros from Running When Workbook Opened via Automation

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Stop Macros from Running When Workbook Opened via Automation

Hi Dave

Thanks for the reply.

I had come across enableevents before and tried it but it didn't seem to
work. I have found another solution for now by using Auto_Open() which only
runs when the workbook is opened in the normal way.

I will have another go with enableevents when I have more time to experiment.

Many thanks
Tim

"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Stop Macros from Running When Workbook Opened via Automation

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Stop Macros from Running When Workbook Opened via Automation

Hi Bob

Yes, my code was identical and yet it seemed to ignore the
xlapp.enableevents = false

Kind regards
Tim ffitch

"Bob Phillips" wrote:

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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Stop Macros from Running When Workbook Opened via Automation


If what you need is to disable the events try with

Application.Enableevents=True/False


--
baldomero
------------------------------------------------------------------------
baldomero's Profile: http://www.excelforum.com/member.php...o&userid=25680
View this thread: http://www.excelforum.com/showthread...hreadid=467820

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop running macros everytime I run excel? SusieOrtiz Excel Discussion (Misc queries) 1 August 18th 09 05:20 AM
How do I stop Excel from opening all files w/macros & running them BobC Excel Discussion (Misc queries) 4 April 5th 09 08:25 PM
How to stop Excel remembering/loading macro from previously opened Workbook Norman Yuan Excel Discussion (Misc queries) 4 June 17th 06 04:13 PM
Running of a Macro when Workbook is opened Darin Kramer Excel Programming 2 December 14th 04 01:06 PM
Workbook opened with macros disabled Alan.Hutchins Excel Programming 1 July 28th 04 09:44 AM


All times are GMT +1. The time now is 03:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"