View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Open a form from an Add-In

I'd use:

Dim wkbk As Workbook
Dim MenuItem As CommandBarControl
Dim NewMenu As CommandBar

Set wkbk = Workbooks("myaddin.xla")

Set NewMenu = Application.CommandBars("somename here")

Set MenuItem = NewMenu.Controls.Add _
(Type:=msoControlButton, temporary:=True)
With MenuItem
.Visible = True
.Style = msoButtonCaption
.Caption = "Enter Data"
.OnAction = "'" & wkbk.Name & "'!openDataForm"
End With


scott wrote:

I keep my custom menu in an add-in mymenu.xla. I'm trying to open a form
called "frm_enterData" that resides in a seperate workbook called
myWorkbook. A snipplet of my mymenu.xla menu code that should open the form
is listed in CODE 2.

Do I need to specify the path of the form's workbook's path before the name
of the function that opens the form? If so, what would the syntax be?

CODE:

Sub openDataForm()
frm_enterData.Show
End Sub

CODE 2:

Set MenuItem = NewMenu.Controls.Add _
(Type:=msoControlButton)
With MenuItem
.Caption = "Enter Data"
.OnAction = "openDataForm"
End With


--

Dave Peterson