LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Macro doesn't work when used as Workbook Open event

Hi all,

I'm getting very frustrated by a piece of code I'm using that creates a
command bar when a worbook is opened, adds buttons to it, and then
deletes it on closing. (I admit I filched the code from here!)

It works perfectly when run as a standard macro, but when run as a
Workbook _Open event it fails at the first command.

Here's what it looks like (as far as the first line where it fails.....

Object Explicit
Private Sub Workbook_Open()
'Creates a toolbar named "Pensions"
Dim Pensions As CommandBar
Dim Button As CommandBarButton


' Create the toolbar
Set Pensions = CommandBars.Add

The debugger indicates that it's failing at the Set Pensions and the
mesage is
"Object variable or With block variable not set"

I thought I'd done that with Dim Pensions As CommandBar

Anyway, as I said, this code works perfectly if I run it as a normal
macro, and ONLY fails if I change it to a Workbook Open event!

Any help would be greatly appreciated and might just save my sanity!!!!

Thanks in advance

Phil

 
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 do I email amacro? leo Excel Worksheet Functions 24 August 9th 06 02:47 PM
excel exits unexpectedly or hangs the second time I open workbook r_m_i Excel Discussion (Misc queries) 0 February 9th 06 10:14 PM
Macro giving errors at workbook open kcdonaldson Excel Discussion (Misc queries) 1 December 6th 05 04:15 PM
Issuing macro in workbook from separate workbook Nigel Excel Discussion (Misc queries) 1 May 16th 05 05:46 PM
Does file need to be open for INDIRECT to another workbook to work briancrosier Excel Discussion (Misc queries) 2 December 15th 04 04:25 PM


All times are GMT +1. The time now is 04:06 PM.

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"