Toolbar for a specific workbook

P

Prixton

Hi,
I have some macros that shall only run in a specific workbook. I have made a
toolobar form those macros but I can not make the toolbar appear only when
opening that special workbook. I also want the toolbar to disappear when
closing the workbook.

Thanks for all help
 
J

Joel

If you add MyworkbookName = ThisWorkbook.name to the beginning of the macro.

then add an if statement at the begfinning of the macro

if (strcomp(MyworkbookName, "runwiththisname.xls") = 0) then


end if
 
P

Prixton

Hi Joel,
Thanks for your answer. However I do not understand it.
If my workbook is called aaa.xls and my toolbar is called MyToolbar, how
should the commands be in the macro?

Thanks again
 
J

Joel

Yuou have to look at macros in the tools - Macros - visual Basic editor.

You said you wanted tthe macro which work with the tool bar only to run when
the workbook has a certain name. The tool bars are inside the spreadsheet.

It is like the Workbook is the Family Jones.
Each worksheet (tab) has a name Alice, Bob, Nancy
The Toolbars also have name Thom.

If you name the Workbook Smith you will still have worksheets Alice, Bob,
Nancy, but you won't have toolbar Thom.

bob Jones
 
P

Prixton

Hi Joel,

I am sorry but I still do not understand.

Here is my macro and let us say that my workbook is called Smith.exe, should
the toolbar be called Smith as well?



Here is my macro:

Sub Compress()

'

' Compress Macro

' Macro recorded 2007-02-22 by Gunnel Bengtsson

'

' Keyboard Shortcut: Ctrl+q

'

ActiveSheet.Rows.RowHeight = 13



End Sub

Sub Expand()

'

' Expand Macro

' Macro recorded 2007-02-22 by Prixton

'

' Keyboard Shortcut: Ctrl+e

'

ActiveSheet.Rows.AutoFit



End Sub



How should I complete it?



Thanks again for your help even if I am slow and do not understand
 
J

Joel

here is one example for the Sub Compress. Replace runwiththisname.xls with
your worksheet name. When Ctrl Q is press will only work when the workbook
is named runwiththisname.xls

Sub Compress()

'

' Compress Macro

' Macro recorded 2007-02-22 by Gunnel Bengtsson

'

' Keyboard Shortcut: Ctrl+q

'
if (strcomp(MyworkbookName, "runwiththisname.xls") = 0) then
ActiveSheet.Rows.RowHeight = 13
end if

End Sub
 
P

Prixton

Sorry Joel, but let me take this from the beginning.
I want a toolbar to appear when I open a certain workbook and disappear when
I close my workbook. I have made my macros and my toolbar. That is all
 
J

Joel

The macros you gave me only activate the Hot Keys. they have nothing to do
with displaying toolbars.

I activated the chart toolbar and got the following macro

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/23/2007 by Joel Warburg
'

'
Application.CommandBars("Chart").Visible = True
End Sub
 
G

Gord Dibben

You will have to create the toolbar when the workbook opens and delete it when
the workbook closes.

Ususally done through Workbook_Open code in Thisworkbook module.

See Debra Dalgleish's site for instructions.

http://www.contextures.on.ca/xlToolbar02.html

You don't have to save the workbook as an add-in.


Gord Dibben MS Excel MVP
 
Top