PC Review


Reply
Thread Tools Rate Thread

Dissable Workbook_Open Event in certian cases

 
 
Michael
Guest
Posts: n/a
 
      3rd Dec 2009
I have a MS Access routine that opens a whole bunch of Excel models
and sucks data out into a data base. Problem is since I set it up some
of the excel files now have a Workbook_Open event that gets triggered
when Access Opens the workbooks. The event asks for some user input
which I want to avoid when opened by Access.

Is there a way for Excel to tell that it is being opend by VBA in
Access as opposed to the user opening the file?

This is how I am opening the workbooks from Excel
Set xlsApp = CreateObject("Excel.application")
Set wb = xlsApp.Workbooks.Open(Path & Filename, , True)

Any ideas would be appreciated.

Thanks.
 
Reply With Quote
 
 
 
 
AB
Guest
Posts: n/a
 
      3rd Dec 2009
I'm not sure if it's possible - as in Excel there is no 'shift' (to
override startup) as in Access, although I might be wrong.

For what's my 0.02$ worth:
- if your access is just getting data from Excel and not putting
anything in back - then i don't think you need to open them up - just
link/import the excel data without even opening them up;

- if you indeed need to open them up you could modify your excel file
this way:
-- have the Workbook_Open routine do nothing but launch another
routine 'ontime' - like 2 seconds after opening the file. The OnTime
routine would do what previously the Workbook_Open used to do
-- add a custom property to your Wrokbook - something like Public
NotRunOnTime As Boolean (it would default to False)
-- have the OnTime routine check NotRunOnTime property and exit if
TRUE
-- when opening the wb from Access - the Workbook_Open will set the
2 sec timer for the OnTime to run but within the 2 sec you set the new
property (NotRunOnTime) to TRUE controling the .xls from Access. Then
after the 2 sec OnTime will see that NotRunOnTime=TRUE and will exit
not launching the whole code . Make sure to close the wb at the end
and not save the NotRunOnTime=true).

Just brainstorming but maybe will give you some ideas.


On Dec 3, 7:57*pm, Michael <mfg...@gmail.com> wrote:
> I have a MS Access routine that opens a whole bunch of Excel models
> and sucks data out into a data base. Problem is since I set it up some
> of the excel files now have a Workbook_Open event that gets triggered
> when Access Opens the workbooks. The event asks for some user input
> which I want to avoid when opened by Access.
>
> Is there a way for Excel to tell that it is being opend by VBA in
> Access as opposed to the user opening the file?
>
> This is how I am opening the workbooks from Excel
> * * * Set xlsApp = CreateObject("Excel.application")
> * * * Set wb = xlsApp.Workbooks.Open(Path & Filename, , True)
>
> Any ideas would be appreciated.
>
> Thanks.


 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      3rd Dec 2009
That seems like a workaround that might work but I was hoping to find
something that could tell the difference between a user opening it and
Access opening it? Is there a way to distiguish? If so then I just add
an if statement to On Open event.
 
Reply With Quote
 
Paul C
Guest
Posts: n/a
 
      3rd Dec 2009
Within Excel and Excel VBA

Application.EnableEvents=false will suppress the event triggers and
Application.EnableEvents=true will turn them back on.

Since you are starting in Access you may have to do some fiddling to get
Access code to suppress Excel events. I am not if this line in Access code
will suppress the Excel event and I am not sure of the exact syntax to cross
applications.

Something like xlsApp.EnableEvent=false may work.

Hope this at least points you in the right direction.



--
If this helps, please remember to click yes.


"Michael" wrote:

> I have a MS Access routine that opens a whole bunch of Excel models
> and sucks data out into a data base. Problem is since I set it up some
> of the excel files now have a Workbook_Open event that gets triggered
> when Access Opens the workbooks. The event asks for some user input
> which I want to avoid when opened by Access.
>
> Is there a way for Excel to tell that it is being opend by VBA in
> Access as opposed to the user opening the file?
>
> This is how I am opening the workbooks from Excel
> Set xlsApp = CreateObject("Excel.application")
> Set wb = xlsApp.Workbooks.Open(Path & Filename, , True)
>
> Any ideas would be appreciated.
>
> Thanks.
> .
>

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      4th Dec 2009
Except for the missing s end the end of EnableEvents, which took me a
minute to figure out, this worked perfectly.

Thank you very muchl
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Block certian users from accessing certian domains\IP adress harryguy082589@gmail.com Windows XP General 4 19th Jan 2006 10:05 PM
Block certian users from accessing certian domains\IP adress harryguy082589@gmail.com Windows XP Help 4 19th Jan 2006 10:05 PM
Block certian users from accessing certian domains\IP adress harryguy082589@gmail.com Windows XP Networking 4 19th Jan 2006 10:05 PM
Block certian users from accessing certian domains\IP adress harryguy082589@gmail.com Windows XP Security 4 19th Jan 2006 10:05 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Microsoft Excel Programming 0 24th Sep 2003 03:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:58 PM.