PC Review


Reply
Thread Tools Rate Thread

How do I auto run my macro upon open of file....Workbook_Open() is NOT working?

 
 
meghantrus@hotmail.com
Guest
Posts: n/a
 
      1st Jun 2007
I need to run a Macro named UpdateData upon open of the file.
This code is not working. I placed the below code in ThisWorkbook.
I am able to manually run UpdateData, but it does not run
automatically when I open the file.
Security is set to Medium and I enable Macro's when I open the file.
What am I doing wrong?


Private Sub Workbook_Open()
Call UpdateData
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      1st Jun 2007
Try this
Run "UpdateData"

"(E-Mail Removed)" wrote:

> I need to run a Macro named UpdateData upon open of the file.
> This code is not working. I placed the below code in ThisWorkbook.
> I am able to manually run UpdateData, but it does not run
> automatically when I open the file.
> Security is set to Medium and I enable Macro's when I open the file.
> What am I doing wrong?
>
>
> Private Sub Workbook_Open()
> Call UpdateData
> End Sub
>
>

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      1st Jun 2007
Your Events may be disabled. Try running this code to reset events. Then
retry your code...

Sub ResetEvents
application.enableevents = true
end sub

Note that enable events is one of those persistent settings that you need to
be very careful with. If you turn it off it will never get turned back on
again unless you do so...
--
HTH...

Jim Thomlinson


"(E-Mail Removed)" wrote:

> I need to run a Macro named UpdateData upon open of the file.
> This code is not working. I placed the below code in ThisWorkbook.
> I am able to manually run UpdateData, but it does not run
> automatically when I open the file.
> Security is set to Medium and I enable Macro's when I open the file.
> What am I doing wrong?
>
>
> Private Sub Workbook_Open()
> Call UpdateData
> End Sub
>
>

 
Reply With Quote
 
Ken
Guest
Posts: n/a
 
      1st Jun 2007
I think either Call UpdateData or Run "UpdateData" should work. Make
sure the Workbook_Open code is attached to the ThisWorkbook object,
and not in a regular module.

Good luck.

Ken
Norfolk, Va


On Jun 1, 10:54 am, Mike <M...@discussions.microsoft.com> wrote:
> Try this
> Run "UpdateData"
>
>
>
> "meghant...@hotmail.com" wrote:
> > I need to run a Macro named UpdateData upon open of the file.
> > This code is not working. I placed the below code in ThisWorkbook.
> > I am able to manually run UpdateData, but it does not run
> > automatically when I open the file.
> > Security is set to Medium and I enable Macro's when I open the file.
> > What am I doing wrong?

>
> > Private Sub Workbook_Open()
> > Call UpdateData
> > End Sub- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
Dave Thomas
Guest
Posts: n/a
 
      15th Jul 2007
Suggest you go into visual basic, select This Workbook, double click and
step through the code one line at a time using function key F8. You'll see
what the code does.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I need to run a Macro named UpdateData upon open of the file.
> This code is not working. I placed the below code in ThisWorkbook.
> I am able to manually run UpdateData, but it does not run
> automatically when I open the file.
> Security is set to Medium and I enable Macro's when I open the file.
> What am I doing wrong?
>
>
> Private Sub Workbook_Open()
> Call UpdateData
> End Sub
>
>



 
Reply With Quote
 
Harlan Grove
Guest
Posts: n/a
 
      26th Jul 2007
meghant...@hotmail.com wrote...
>I need to run a Macro named UpdateData upon open of the file.
>This code is not working. I placed the below code in ThisWorkbook.
>I am able to manually run UpdateData, but it does not run
>automatically when I open the file.
>Security is set to Medium and I enable Macro's when I open the file.
>What am I doing wrong?
>
>Private Sub Workbook_Open()
> Call UpdateData
>End Sub


If for some reason Application.EnableEvents had been set to FALSE, no
event handlers would run, not even Open events. However, with the file
open, you could define the name Auto_Open referring to

='YourFilenameHere.xls'!ThisWorkbook.Workbook_Open

and it'll run on opening if you enable macros even if EnableEvents
were set to FALSE. However, it'd run twice if EnableEvents were set to
TRUE. You'd need to add a state variable to prevent that.

Private Sub Workbook_Open()
Static st As Boolean
If Not st Then
Call UpdateData
st = True
End If
End Sub

Even so, if UpdateData throws a runtime error, and you end it, the
static variable st will reset to FALSE, so this would try to run
UpdateData a second time. You could use a defined name or a worksheet
cell as the state variable, but that'd mark the file as modified
(which may not be a big deal).

 
Reply With Quote
 
FrankSinatra
Guest
Posts: n/a
 
      19th Sep 2007
I dont know if this will help, but I always forget that the "Private
Sub Workbook_Open()" statements have to go in the "Microsoft Excel
Objects" section of the VBA Project, in "ThisWorkbook".

The mistake I make almost everytime is to first look for the Open
command in the drop down boxes above the VBA coding window, and it is
not there of course. Then I check in the Excel Help and find the
"Private Sub Workbook_Open()" command example and do some macro
recording to get close to what I what the spreadsheet to do on Open.
Then I drop that into Module1 of the modules section, and of course
that doesnt work---but I am closer! More frustrated, but closer. So
the next thing I do is figure I need to rename Module1 to AutoExec,
but that doesnt work either.

So I then fish around for an old Excel file I have where the "on Open"
code works, and viola. I move the code I just wrote out of Module1/
Autoexec and into "ThisWorkbook" and it runs fine.

Take care.
Keving Gaza

"What you focus on, you enlarge."
Stedman Graham

 
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
open a workbook without running Workbook_Open macro in E2007 Andreas Microsoft Excel Programming 10 7th Jul 2009 06:41 PM
Macro runs upon wkbk open, but no Workbook_Open or Auto_Open Macro =?Utf-8?B?Um9uIENvZGVycmU=?= Microsoft Excel Programming 2 26th Sep 2006 05:50 PM
How to auto activate macro when file open ? =?Utf-8?B?Ym9uemlv?= Microsoft Excel Worksheet Functions 1 16th Dec 2005 02:45 PM
Auto run macro on *.csv file open =?Utf-8?B?Q1AgUG9l?= Microsoft Excel Programming 4 4th Mar 2005 06:25 PM
Auto run macro on open file =?Utf-8?B?RGlhbmUgQWxzaW5n?= Microsoft Excel Programming 2 16th Feb 2005 02:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:48 AM.