How do I add multiple user macros to the toolbar?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
pmcevoy
Posts: 2
Joined: Wed Sep 02, 2009 12:36 pm

How do I add multiple user macros to the toolbar?

Post by pmcevoy »

When right click on the toolbar and select customize, then go macros in the command tab the only macro i see is 'User Macro' regardless of how many I have. I expected to see all the macros i've created.

thanks in advance for any help.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

From the Main Menu:
Configure/Preferences/Macros
Select the macros in the left column and add them to the column on the right side.
Apply and OK your way out.

You should now see your macros on the Main Menu/Macros drop down.
========================
When making configuration changes I find it best to follow these steps, especially for any changes in Classes:

1. Close all other copies of TextPad.
2. Close all open documents, INCLUDING THE DEFAULT NEW BLANK DOCUMENT.
3. Make the changes you want: Configure/Preferences/......
4. Apply and OK your way out the configurations.
5. Close TextPad.
6. Open TextPad again, and your changes should be good.
Hope this was helpful.............good luck,
Bob
pmcevoy
Posts: 2
Joined: Wed Sep 02, 2009 12:36 pm

Post by pmcevoy »

thanks for that, I actually have that part completed but I'd like to add the Macro as a button. ie I want it on the toolbar. However after i am only seeing 'User Macro' in the list that can be assigned as a button.
derekwallace
Posts: 10
Joined: Thu Sep 11, 2003 7:02 am

Post by derekwallace »

definitely a bug in textpad.
you can add a "User Macro" as a button to the Macro toolbar. It will default to the first macro that you have created in the Macro Menu.
If you have a number of macros in Macro Menu you cannot select which ones to put on the toolbar.
derekwallace
Posts: 10
Joined: Thu Sep 11, 2003 7:02 am

Post by derekwallace »

found out how to do it.

1. Make the Macros toolbar visible View - Toolbars - Macros

2. Customize the tool bar and add a "User Macro" to the toolbar.
- hit Toolbar Options Button (rhs of the toolbar itself)
- Add or Remove Buttons - Customize
- Commands Tab
- Categories - Macros
- Drag the "User Macro" in the commands box to your toolbar.

This adds the first Macro you have in the Macro Menu to the toolbar.
You can add multiple "User Macros", but they are always the first Macro in the macro menu.

3. close textpad.

4. locate the textpad config.xml file and open in an editor other than Textpad!!!!!Really really important.

On windows 7 its stored here.
C:\Users\derek\AppData\Roaming\Helios\TextPad\5.0\config.xml

5. look for this section in the file. This is the Macro Toolbar!!

<CommandBar Class="CXTPToolBar" BarID="551" Flags="63" Style="4194304" Title="Macros" MRUWidth="32767">
<Controls OriginalControls="1">
<Control Class="CGUICmdUserMacros" Id="33109" Caption="User macro" TooltipText="Play back this macro" DescriptionText="Play back this macro"/>
<Control Class="CXTPControlButton" Id="688" Caption="Recorder On/Off" TooltipText="Recorder On/Off" DescriptionText="Record a keystroke macro"/>
<Control Class="CXTPControlButton" Id="689" Caption="Pause Recorder" TooltipText="Pause Recorder" DescriptionText="Pause the keystroke macro recorder"/>
<Control Class="CXTPControlButton" Id="690" Caption="Playback" TooltipText="Playback" DescriptionText="Playback a macro"/>
<OriginalControls>
<Control Class="CXTPControlButton" Id="688" Caption="Recorder On/Off" TooltipText="Recorder On/Off" DescriptionText="Record a keystroke macro"/>
<Control Class="CXTPControlButton" Id="689" Caption="Pause Recorder" TooltipText="Pause Recorder" DescriptionText="Pause the keystroke macro recorder"/>
<Control Class="CXTPControlButton" Id="690" Caption="Playback" TooltipText="Playback" DescriptionText="Playback a macro"/>
</OriginalControls>
</Controls>
</CommandBar>


6. You can customize this toolbar within

In this case ive added 3 of my macros.
The magic number 33109 seems to represent the first Macro that appears in the Menu.
Incrementing the number points to the next macro etc...


<CommandBar Class="CXTPToolBar" BarID="551" Flags="63" Style="4194304" Title="Macros" MRUWidth="32767">
<Controls OriginalControls="1">
<Control Class="CGUICmdUserMacros" Id="33113" Caption="Browse" TooltipText="Play back this macro" DescriptionText="Play back this macro"/>
<Control Class="CGUICmdUserMacros" Id="33110" Caption="Derek" TooltipText="Play back this macro" DescriptionText="Play back this macro"/>
<Control Class="CGUICmdUserMacros" Id="33109" Caption="Wallace" TooltipText="Play back this macro" DescriptionText="Play back this macro"/>

<Control Class="CXTPControlButton" Id="688" Caption="Recorder On/Off" TooltipText="Recorder On/Off" DescriptionText="Record a keystroke macro"/>
<Control Class="CXTPControlButton" Id="689" Caption="Pause Recorder" TooltipText="Pause Recorder" DescriptionText="Pause the keystroke macro recorder"/>
<Control Class="CXTPControlButton" Id="690" Caption="Playback" TooltipText="Playback" DescriptionText="Playback a macro"/>
<OriginalControls>
<Control Class="CXTPControlButton" Id="688" Caption="Recorder On/Off" TooltipText="Recorder On/Off" DescriptionText="Record a keystroke macro"/>
<Control Class="CXTPControlButton" Id="689" Caption="Pause Recorder" TooltipText="Pause Recorder" DescriptionText="Pause the keystroke macro recorder"/>
<Control Class="CXTPControlButton" Id="690" Caption="Playback" TooltipText="Playback" DescriptionText="Playback a macro"/>
</OriginalControls>
</Controls>
</CommandBar>
aimy
Posts: 53
Joined: Mon Nov 01, 2004 4:02 am

Post by aimy »

I was just about to ask the same question..

Thank you so much derek for the solution.. Image

But it seems like quite a cumbersome process I presume?

So why not TextPad just fix this?? :(

Thank you.
razibur
Posts: 1
Joined: Sun Sep 27, 2009 10:35 am

Post by razibur »

Creating a toolbar can be done manually by the menu command View, Toolbars, Customize. On the tab called "Toolbars" one can click the button "New..." to create a new custom toolbar. Excel will ask for a name for the new toolbar and subsequently present an empty toolbar. Watch out: this new toolbar often is hidden by the toolbar customization dialog itself, so this might have to be dragged out of the way to get the new toolbar into view.

Although custom toolbars are also saved to your local xlb file (as discussed in the previous chapter), there is one important difference between a menubar and a toolbar: one can attach a custom toolbar to a workbook.

This is how that works:

* Right click the toolbar and choose "Customize...".
* Click the "Attach..." button, located on the Toolbars tab
* Should the workbook already contain an identically named toolbar, then this one needs to be removed first by selecting it on the right-hand side and clicking delete.
* Select the new toolbar on the left-hand side of the dialog (see figure below) and click "Copy". Make sure your toolbar is completely finished before doing this though.


The Attach Toolbars dialog screen.

Note that any changes that are made to a custom toolbar are updated to the system version of the toolbar, not to the attached version. So when changes have been made, the attaching process needs to be repeated.

So what exactly happens when a workbook with an attached toolbar is opened?

Excel checks the user's .xlb file to see whether the toolbar is already on the system. If so, nothing is done and the local copy of the toolbar is used. If not, then Excel copies the toolbar from the workbook into the user's toolbar customization file. This means, that when one needs to be sure the user gets the most recent copy of a toolbar, the toolbar has to be removed from the system at closing of the workbook. That way, at every load of the workbook, the workbook toolbar will be used.

When the file containing the toolbar is saved as a new file, Excel will automatically update the references in the system toolbar to the NEW workbook. This can have very confusing effects: When one loads an older copy of the workbook and clicks one of the toolbar buttons, Excel will try to load the latest copy of the workbook, since that is what the toolbar's buttons will refer to. This confusion can only be avoided by making sure the toolbar is deleted from the system when the workbook is closed. Listing 2 shows the relevant code.

Listing 2

(In the Thisworkbook module)
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars("YourBar").Delete
End Sub

Of course opening two workbooks with this toolbar will have the unwanted effect, that the toolbar will only refer the macros in the first workbook. Closing either workbook will then remove the toolbar from the system, leaving a workbook without a steering wheel. Closing and reopening the file of course brings back the toolbar.

Situations like these arise when one has multiple copies of a file that contains macros to control the file. Such a situation calls for creation of an add-in that contains the macros, which are then separated from the multiple copies of the workbook. Maintenance of the macros will be much easier in such a case.
Create a Custom Toolbar programmatically

Creating a toolbar and adding a button to it is shown in the code in listing 3.

Listing 3
Option Explicit

Sub RemoveBar()
On Error Resume Next
Application.CommandBars("xlUtilDemo1").Delete
End Sub

Sub CreateBar()
Dim oBar As CommandBar
Dim oControl As CommandBarControl
RemoveBar
Set oBar = Application.CommandBars.Add
oBar.Name = "xlUtilDemo1"
oBar.Visible = True
Set oControl = oBar.Controls.Add(ID:=1, Before:=1)
oControl.OnAction = "ButtonClicked"
oControl.FaceId = 275
oControl.Caption = "Click me!"
Set oControl = Nothing
Set oBar = Nothing
End Sub

Sub ButtonClicked()
MsgBox "Your button works!!!"
End Sub

The Sub Createbar creates one custom toolbar with one button, attached to the sub "ButtonClicked".

To make sure the toolbar is created at workbook open and destroyed at closure, the thisworkbook module should contain the following code:

Listing 4
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
RemoveBar
RemoveMenu
End Sub

Private Sub Workbook_Open()
CreateBar
MakeMenu
End Sub


There is a disadvantage to this method. When the user decides to cancel a shutdown of Excel (or closing the workbook), the Workbook_BeforeClose event code has already run, so the toolbar is destroyed, even though Excel hasn't been closed. To make sure the toolbar returns after such a cancellation, the code needs some modification.

1. Add a public variable to a normal module:
Public bMeClosing As Boolean

And change the code in the ThisWorkbook module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RemoveBar
RemoveMenu
If Not bMeClosing Then
Application.OnTime Now, "Createbar"
Application.OnTime Now, "MakeMenu"
End If
End Sub

So how does this work?
When the user closes Excel himself, the variable "bMeClosing" will be False and an OnTime event is scheduled which will run the CreateBar subroutine immediately after Excel has finished handling all events it needs to handle during its closing routine, including saving unsaved workbooks, etcetera.

If the user decides to cancel the closing operation, then the OnTime event will fire and the toolbar gets rebuilt. If however the user does not cancel the closure, nothing happens, because Excel has shut down.

A special situation arises when only the workbook with the code is to be closed (e.g. when an add-in is uninstalled). Then the Workbook_BeforeClose code runs, sets the OnTime event and the workbook closes. But immediately Excel will load the workbook again to process the scheduled OnTime event. It will even show the enable macros dialog again.

To shut down the utility itself, one needs to change the value of bMeClosing to true and subsequently close. In any normal module:
Sub CloseMeNow()
bMeClosing = True
ThisWorkbook.Close
End Sub




Mengembalikan Jati Diri Bangsa|
Kenali Dan Kunjungi Objek Wisata Di Pandeglang
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

razibur wrote:Creating a toolbar can be done manually by the menu command View, Toolbars, Customize. On the tab called "Toolbars" one can click the button "New..." to create a new custom toolbar. Excel will ask
You might not have noticed, but this is a forum for the text editor TextPad, not for Excel ...
Post Reply