View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default custom toolbar for each sheet in workbook?

I didn't discuss it, but yes, I have also run into the problem of lines being
red because of the way the copy/paste works in here. But you are correct, if
it is red, either put a space and an underscore at the end of the previous
line, or move the current line to line up with the end of the previous line.
Of course, the space underscore will not work if it is captured in a quoted
line. Like:

Msgbox("This is an example of a _
broken line that will not work right. :)")

Where it should say
Msgbox("This is an example of a broken line that will not work right. :)")
'<-- although now the text statement is incorrect because it is no longer a
broken line. :) But you get the gest.


"davegb" wrote:


GB wrote:
In the end... It's actually quite easy from the code I've written. Anytime I
want to "develop" a new toolbar. I go into two areas:

Function Name():
I change the name of the toolbar that I'm trying to use to something unique,
that I hopefully have never developed before/expect to use at the same time
that I'm using this new toolbar.


Ok, I'm going to give this a try. I'll start with a few basic questions
trying to clarify how the macro works. If your patience holds up, I'll
ask more about specific code.
I put your code in a module and rearranged a bit because going from a
module to here to a module, there were lots of lines of red which were
mostly continuations from the previous line.
From your description above, I'm guessing that the code starts at

"Function Name". Is this called by a particular worksheet being
activated? I don't see it being called anywhere else in the code. If
not, then why is it a function instead of just a subroutine?

Looking at Function Name, I'm not clear on what the Select Case
statement is based. Where is "Value" defined? I know it's a zero or a
1, but I can't find where it comes from.
If it's a zero, the toolbar gets named "First Tool Bar", if not, it
doesn't get named.
Finally, since it ends after the Select Case command is executed, how
does the rest of the code get run? Is there more code back at the sheet
itself that calls some other code after Function Name is run?


And then I go into the appropriate Tool_Bar(Number)_Props:
for example Tool_Bar1_Props.
And I revise the toolbar to what I want. If I want a button in a group,
then I use:
Set NewItem =
Application.CommandBars(Name(0)).Controls.Add(Type :=msoControlButton)
And then I work with the NewItem (Control Button)

And if I want a Drop down menu to work with, then I:
Set NewItem =
Application.CommandBars(Name(0)).Controls.Add(Type :=msoControlPopup,
Temporary:=True)

And then for every button or item I want to add to that drop down, I use the
newItem and set a ctrl1 variable. The help files on commandbars will tell
you about the different Types, and things like Temporary.

The other thing that I have to change depending on what I expect of the
particular button is the .OnAction command. It has to refer to a procedure
that will do what I want.

In the example provided, if you make a module that is named ModuleName
(Instead of Module1 for example) that has say the public sub routine Move2Del
and Select the drop down menu of the newly created Excel menu that appears
and select the one that says move to the delete folder, it will run whatever
you have programmed in Move2Del.

The FaceId's that I have selected correspond to the actions that I desired
and were fairly readily available.

All in all, the hard part is done for you. And if you get the code into VBA
you will see that like a lot of the Tool_Bar1_Props lines are commented out.
But I have done some different things in there that I do not want to lose so
that if I wish to implement them in the future I have them readily available.

Chr(13) + Char(10) just gives a new line of text
A line ending with an underscore is so that I can have "one" line of code
that I can see completly on the screen and on printouts. It tells VBA that
hey, don't stop processing the next line of code as part of the current line.

If you want to Show ToolBar1 (which in this code, I only implemented one)
then you call Tool_Bar1_Show. The error handling will ensure that it will
appear.

One thing that I forgot to mention was that when the workbook loses focus,
the toolbars should be "put away" or deleted. And then when the workbook
regains focus, the appropriate toolbar(s) should be shown again.

"davegb" wrote:

Wow! Thanks for your reply.
Looks overwhelming. I'm not sure I can figure this one out. I had no
idea it would be this complicated. There are several kinds of syntax
I've never even used before. I think this one's just beyond me at this
point!