LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default AddIn Name Resolution

Using Excel 2003 under Win XP Pro; all current updates installed for both
products.

I've encountered unexpected behavior with respect to name resolution between
an AddIn and a Workbook. To test Excel's behavior, I created a simple
example. I created a Workbook named MySub.xls, saved it, and then saved it
as an AddIn named MySub.xla. I then added some code to the AddIn to create a
toolbar. The entire code for both is presented. All code resides within the
respective ThisWorkbook module:

For the Workbook MySub.xls:

Public Sub MySub()
MsgBox "Workbook::MySub()"
End Sub


For the AddIn MySub.xla:

Public Sub MySub()
MsgBox "AddIn::MySub()"
End Sub

Private Sub MakeToolbar()
Dim tb As CommandBar
Dim btn As CommandBarButton

Set tb = Application.CommandBars.Add("MySub", msoBarTop)
tb.Visible = True

Set btn = tb.Controls.Add(Type:=msoControlButton)
With btn
.FaceId = 59
.OnAction = "ThisWorkbook.MySub"
.TooltipText = "MySub"
End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("MySub").Delete
End Sub

Private Sub Workbook_Open()
MakeToolbar
End Sub

As you can see, both the AddIn and the Workbook have identical Subs named
MySub. However, when I click on the tollbutton in the AddIn's toolbar, it
executes not the AddIn's version but rather the Workbook's! Thus if I write
an AddIn and a user's workbook just happens to have a Sub with the same
signature my code would not execute properly. This seems like a bona fide
bug in VBA to me. Am I missing something?


 
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
Screen Resolution Ronbo Excel Programming 2 January 17th 05 08:45 PM
Screen Resolution Sheldon Excel Programming 1 November 2nd 04 05:52 PM
xlVeryHidden Resolution kevin Excel Programming 1 June 2nd 04 01:08 AM
Screen resolution Arkimediz Excel Programming 3 April 1st 04 05:23 PM
Remove Excel AddIn from AddIn List !! Help carl Excel Programming 2 December 8th 03 03:36 PM


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

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

About Us

"It's about Microsoft Excel"