Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Calling Sub with Parameter from Menuitem

My problem is the following:
I want to create something similar to the "recent file list" in Excel,
except that I want my file list to be fairly constant (I know how to take
care of the updating, etc). But I cannot figure out how to make the
menuitem open the file specified by the path in the menuitem caption.

I have tried making the .OnAction property =
"myFile!DispMyName(""C:\...path..."")", with strange results. Whenever I
run the menuitem, it runs part of the procedure specified. The parameter
passing worked correctly. The sub printed the myName variable to the
immediate window. However, the 2nd statement did not work.

Strangely, this sub was run twice, printing the myName variable twice (and
when i substittuted MsgBox for debug.print, it msgbox'ed me twice). More
strangely, I put break points on every line in the code, but the code just
executed (twice) without stopping.

Is there a better way to do what I am thinking of? I only want there to be
a single procedure, if possible, that is called by the menuitems. If this
is not possible, having 9 almost-identical procedures is ok, but then I
would still need a way to properly pass the file path... perhaps if i had 9
procedures, they could each find the n'th menuitem, parse its caption, and
use that... but I am not even sure how to do that either.

Any help would be appreciated.


Public Sub DispMyName(Optional myName As String = "")
Debug.Print myName
Workbooks.Open myName
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Calling Sub with Parameter from Menuitem

You don't need to pass a parameter: Assuming the caption contains the fully
qualified filename:

Public Sub DispMyName()
Debug.Print CommandBars.ActionControl.Caption
Workbooks.Open CommandBars.ActionControl.Caption
End Sub

--
Regards,
Tom Ogilvy


"R Avery" wrote in message
...
My problem is the following:
I want to create something similar to the "recent file list" in Excel,
except that I want my file list to be fairly constant (I know how to take
care of the updating, etc). But I cannot figure out how to make the
menuitem open the file specified by the path in the menuitem caption.

I have tried making the .OnAction property =
"myFile!DispMyName(""C:\...path..."")", with strange results. Whenever I
run the menuitem, it runs part of the procedure specified. The parameter
passing worked correctly. The sub printed the myName variable to the
immediate window. However, the 2nd statement did not work.

Strangely, this sub was run twice, printing the myName variable twice (and
when i substittuted MsgBox for debug.print, it msgbox'ed me twice). More
strangely, I put break points on every line in the code, but the code just
executed (twice) without stopping.

Is there a better way to do what I am thinking of? I only want there to

be
a single procedure, if possible, that is called by the menuitems. If this
is not possible, having 9 almost-identical procedures is ok, but then I
would still need a way to properly pass the file path... perhaps if i had

9
procedures, they could each find the n'th menuitem, parse its caption, and
use that... but I am not even sure how to do that either.

Any help would be appreciated.


Public Sub DispMyName(Optional myName As String = "")
Debug.Print myName
Workbooks.Open myName
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Calling Sub with Parameter from Menuitem

Excellent. That is precisely what I needed.

Thanks!


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
Parameter Query Lee Excel Discussion (Misc queries) 4 October 12th 09 07:38 PM
How to choose if I use a parameter or not in a parameter query Arnaud Excel Discussion (Misc queries) 0 March 8th 07 01:19 PM
parameter query help marcus Excel Discussion (Misc queries) 0 September 30th 05 12:49 PM
Parameter Query? AcesUp Excel Discussion (Misc queries) 2 August 22nd 05 10:32 PM
Getting the Label or Caption of MenuItem Selected Brian Stigler Excel Programming 1 January 22nd 04 04:48 PM


All times are GMT +1. The time now is 08:07 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"