Thread: Custom Menu
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Custom Menu

Todd,

The OnAction property must be a macro name, not a VBA statement.
Thus, create a macro that closes the file

Sub CloseFile()
Workbooks("Report3.xls").Close
End Sub

and assign that macro to the OnAction property:

..OnAction = "CloseFile"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Todd Huttenstine" wrote in
message ...
Hey guys I have a menu on the menu bar at the top of excel
called "Reports". Its right after the menu item "Help" at
the top. When you click on Reports, a drop down menu
comes out and in that meru is an item called "Uninstall"
Below is my code that creates it.

Here is my code...
With ctrlPopUp
Set ctrlButtonA = .Controls.Add
(Type:=msoControlButton, ID:=1)
ctrlButtonA.Caption = "Uninstall"
ctrlButtonA.Style = msoButtonCaption
End With
ctrlButtonA.OnAction = Workbooks("Report3").Close

When I click on Uninstall, I want it to close the workbook
called "Report3.xls".

However when I try to code this in the onaction part of my
code, I get the error message: "Expected Function or
Variable" and it highlights the .Close on the last line of
my code (above).

I need to be able to hardcode this into the code. I do
not want to create a module and have this code in it and
then reference this code in the onaction. I need to have
the close workbook "Report3.xls" hardcoded in the
Uninstall menu item click.

How do I do this?


Thank you
Todd Huttenstine