Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
max max is offline
external usenet poster
 
Posts: 3
Default .OnAction with arguments

Hi,

I'm using VB 6.3 with Excel 2000 in Win2000.

I am trying to create menu items that call procedures in modules. The
procedures have arguments, for example

Sub DoSomeThing(Arg1 As String, Arg2 As Boolean)

When creating the menu item, I have a pretty arcane attempt...


Set SubMenuItem = MenuItem.Controls.Add _
(Type:=msoControlButton)
With SubMenuItem
.Caption = "Process File"
.Tag = "blah"
'.OnAction = "'Module1.DoSomeThing """ & .Tag & """ False'"
End With

(picked this up from newsgroup but don't quite get it)

The message back is

The macro "C:\temp\ThisFile.xls'!'Module1.DoSomeThing "blah" False"
cannot be found.


Any ideas? Thanks in advance,

Max
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default .OnAction with arguments

Max,

The argument values must be separated a comma:

.OnAction = "'Module1.DoSomeThing """ & .Tag & """, False'"


--

John Green - Excel MVP
Sydney
Australia


"max" wrote in message om...
Hi,

I'm using VB 6.3 with Excel 2000 in Win2000.

I am trying to create menu items that call procedures in modules. The
procedures have arguments, for example

Sub DoSomeThing(Arg1 As String, Arg2 As Boolean)

When creating the menu item, I have a pretty arcane attempt...


Set SubMenuItem = MenuItem.Controls.Add _
(Type:=msoControlButton)
With SubMenuItem
.Caption = "Process File"
.Tag = "blah"
'.OnAction = "'Module1.DoSomeThing """ & .Tag & """ False'"
End With

(picked this up from newsgroup but don't quite get it)

The message back is

The macro "C:\temp\ThisFile.xls'!'Module1.DoSomeThing "blah" False"
cannot be found.


Any ideas? Thanks in advance,

Max



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default .OnAction with arguments

I'd do it slightly differently:

Creating the menu item:

Set SubMenuItem = MenuItem.Controls.Add _
(Type:=msoControlButton)
With SubMenuItem
.Caption = "Process File"
.Tag = "blah"
.Parameter = "False"
.OnAction = "DoSomeThing"
End With

In the macro:

Public Sub DoSomething()
Dim Arg1 As String
Dim Arg2 As Boolean

With Application.ActiveControl
Arg1 = .Tag
Arg2 = (.Parameter = "True")
End With



In article ,
(max) wrote:

Hi,

I'm using VB 6.3 with Excel 2000 in Win2000.

I am trying to create menu items that call procedures in modules. The
procedures have arguments, for example

Sub DoSomeThing(Arg1 As String, Arg2 As Boolean)

When creating the menu item, I have a pretty arcane attempt...


Set SubMenuItem = MenuItem.Controls.Add _
(Type:=msoControlButton)
With SubMenuItem
.Caption = "Process File"
.Tag = "blah"
'.OnAction = "'Module1.DoSomeThing """ & .Tag & """ False'"
End With

(picked this up from newsgroup but don't quite get it)

The message back is

The macro "C:\temp\ThisFile.xls'!'Module1.DoSomeThing "blah" False"
cannot be found.


Any ideas? Thanks in advance,

Max

  #4   Report Post  
Posted to microsoft.public.excel.programming
max max is offline
external usenet poster
 
Posts: 3
Default .OnAction with arguments

John and JE,

Thanks for your replies. I finally got it to work.

John - I tried the comma and it didn't work on my machine (but
strangely, it did work on someone else's).

JE - I couldn't find ActiveControl documented anywhere (and the code
bombed on it).

What did work was

Application.CommandBars.ActionControl.Tag

and

Application.CommandBars.ActionControl.Parameter

Thanks for the help,

Max
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default .OnAction with arguments

thanks for the correction - that's what happens when I fail to test my
memory (doesn't happen often - I test most everything).

In article ,
(max) wrote:

JE - I couldn't find ActiveControl documented anywhere (and the code
bombed on it).

What did work was

Application.CommandBars.ActionControl.Tag

and

Application.CommandBars.ActionControl.Parameter

Thanks for the help,

Reply
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
Macro - onAction arguments version83 Excel Worksheet Functions 2 April 10th 10 09:59 PM
How do you add arguments to an OnAction event? Jason[_27_] Excel Programming 5 November 21st 03 12:48 PM
OnAction Jim Rech Excel Programming 1 September 5th 03 04:39 PM
.OnAction - Multiple Calls Matt[_9_] Excel Programming 2 August 9th 03 09:07 PM
OnAction Richard Yang Excel Programming 1 July 15th 03 01:37 PM


All times are GMT +1. The time now is 11:26 AM.

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"