Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Link macro to a toolbar?

Lars,

You're welcome!

Hope the macros I sent were part of the solution.

I just sent you everything so you could see it.

--
sb
"Lars Peter Nielsen" wrote in message
k...
Thx. I got the idea and changed a little in the code, so it was much more
simpel and it works perfectly. Thx.

LPN

"steve" skrev i en meddelelse
...
Lars,

See the macros below. They go into the ThisWorkbook module.
The beforeclose macro deletes the toolbar. (amend per your needs).
The open macro creates the toolbar.
The OnAction sets the macro to be run by each button.
The face ID # was gotton from a special workbook showing the different
choices and their number.
You position the toolbar with
cbrCommandBar.Position = msoBarTop
check out help for other options.

[all code "stolen" from this ng]

Copy and paste into a workbook and watch it run. (of course you won't

have
the associated macros for the buttons to run).

steve

=============================================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars(" Prepare Request ").Delete
End Sub

Private Sub Workbook_Open()
'Private Sub Workbook_Activate()
Sheets(1).Cells(1, 1) = Application.UserName
Dim cbrCommandBar As CommandBar
Dim cbcCommandBarButton As CommandBarButton

Application.DisplayAlerts = False
Application.ScreenUpdating = False
' Application.DisplayFullScreen = True

' If the command bar exits, remove it.
On Error Resume Next
Application.CommandBars(" Prepare Request ").Delete

' Add the command bar to the application's
' CommandBars collection.
Set cbrCommandBar = _
Application.CommandBars.Add
cbrCommandBar.Name = " Prepare Request "

' Add command button control to the control's
' collection of CommandBar objects.

' Prepare Request
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " New Request "
.FaceId = 139
.TooltipText = _
"Press me to Prepare Request."
.OnAction = "QuoteCreate"
.Tag = "Quoter"
End With

End With

' Add Reps/Service personnel
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Add Sales/CS "
.FaceId = 2131
.TooltipText = _
"Press me to Add."
.OnAction = "AddRS"
.Tag = "AddRS"
End With

End With

' Delete Reps/Service personnel
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Delete Sales/CS "
.FaceId = 1657
.TooltipText = _
"Press me to Delete."
.OnAction = "DeleteRS"
.Tag = "DeleteRS"
End With
End With

' Amend Quote
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Amend Request "
.FaceId = 593
.TooltipText = _
"Press me to Amend Request."
.OnAction = "QuoteAmend"
.Tag = "Amend"
End With
End With

' Send email
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Send email "
.FaceId = 1981
.TooltipText = _
"Press me to email Quote."
.OnAction = "SendMyMail"
.Tag = "emailquote"
End With
End With

cbrCommandBar.Visible = True
cbrCommandBar.Position = msoBarTop

' For Each sht In ActiveWorkbook.Sheets
' sht.Protect _
' password:="", _
' DrawingObjects:=True, _
' Contents:=True, _
' Scenarios:=True, _
' Userinterfaceonly:=True
' Next sht

Set cbrCommandBar = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

Sub CommandBarDelete()
On Error Resume Next
Application.CommandBars(" Prepare Request ").Delete
End Sub

--
sb
"Lars Peter Nielsen" wrote in message
k...
Hi

I have made a macro which create a toolbar with the following buttons:

Sub toolbar()
'
' toolbar Makro
' Makro indspillet 21-08-2003 af Lars P
'

'
Application.CommandBars.Add(Name:="Zoom").Visible = True
Application.CommandBars("Zoom").Controls.Add

Type:=msoControlButton,
ID:= _
2949, Befo=1
Application.CommandBars("Zoom").Controls.Add

Type:=msoControlButton,
ID:= _
2949, Befo=2
Application.CommandBars("Zoom").Controls.Add

Type:=msoControlButton,
ID:= _
2949, Befo=3
Application.CommandBars("Zoom").Controls.Add

Type:=msoControlButton,
ID:= _
2949, Befo=4
Application.CommandBars("Zoom").Controls.Add

Type:=msoControlButton,
ID:= _
2949, Befo=5
End Sub

**************

How can I rename these buttons and link a macro to it - all in the

same
code?? I want to put it into a autoopen, so I get this toolbar up

which
is
used for the workbook and then I can also share the workbook with

others
who
hasnt made this toolbar - of course I will delete it when I close the
workbook (autoclose). Is it also possible to let it the toolbar go up

to
the
other toolbars (so its not just in the middle of everything)?

Rgds Lars









  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Link macro to a toolbar?

Thx. I got the idea and changed a little in the code, so it was much more
simpel and it works perfectly. Thx.

LPN

"steve" skrev i en meddelelse
...
Lars,

See the macros below. They go into the ThisWorkbook module.
The beforeclose macro deletes the toolbar. (amend per your needs).
The open macro creates the toolbar.
The OnAction sets the macro to be run by each button.
The face ID # was gotton from a special workbook showing the different
choices and their number.
You position the toolbar with
cbrCommandBar.Position = msoBarTop
check out help for other options.

[all code "stolen" from this ng]

Copy and paste into a workbook and watch it run. (of course you won't

have
the associated macros for the buttons to run).

steve

=============================================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars(" Prepare Request ").Delete
End Sub

Private Sub Workbook_Open()
'Private Sub Workbook_Activate()
Sheets(1).Cells(1, 1) = Application.UserName
Dim cbrCommandBar As CommandBar
Dim cbcCommandBarButton As CommandBarButton

Application.DisplayAlerts = False
Application.ScreenUpdating = False
' Application.DisplayFullScreen = True

' If the command bar exits, remove it.
On Error Resume Next
Application.CommandBars(" Prepare Request ").Delete

' Add the command bar to the application's
' CommandBars collection.
Set cbrCommandBar = _
Application.CommandBars.Add
cbrCommandBar.Name = " Prepare Request "

' Add command button control to the control's
' collection of CommandBar objects.

' Prepare Request
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " New Request "
.FaceId = 139
.TooltipText = _
"Press me to Prepare Request."
.OnAction = "QuoteCreate"
.Tag = "Quoter"
End With

End With

' Add Reps/Service personnel
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Add Sales/CS "
.FaceId = 2131
.TooltipText = _
"Press me to Add."
.OnAction = "AddRS"
.Tag = "AddRS"
End With

End With

' Delete Reps/Service personnel
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Delete Sales/CS "
.FaceId = 1657
.TooltipText = _
"Press me to Delete."
.OnAction = "DeleteRS"
.Tag = "DeleteRS"
End With
End With

' Amend Quote
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Amend Request "
.FaceId = 593
.TooltipText = _
"Press me to Amend Request."
.OnAction = "QuoteAmend"
.Tag = "Amend"
End With
End With

' Send email
With cbrCommandBar.Controls
Set cbcCommandBarButton = _
.Add(msoControlButton)

' Set properties of the command button.
With cbcCommandBarButton
.Style = msoButtonIconAndCaption
.Caption = " Send email "
.FaceId = 1981
.TooltipText = _
"Press me to email Quote."
.OnAction = "SendMyMail"
.Tag = "emailquote"
End With
End With

cbrCommandBar.Visible = True
cbrCommandBar.Position = msoBarTop

' For Each sht In ActiveWorkbook.Sheets
' sht.Protect _
' password:="", _
' DrawingObjects:=True, _
' Contents:=True, _
' Scenarios:=True, _
' Userinterfaceonly:=True
' Next sht

Set cbrCommandBar = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

Sub CommandBarDelete()
On Error Resume Next
Application.CommandBars(" Prepare Request ").Delete
End Sub

--
sb
"Lars Peter Nielsen" wrote in message
k...
Hi

I have made a macro which create a toolbar with the following buttons:

Sub toolbar()
'
' toolbar Makro
' Makro indspillet 21-08-2003 af Lars P
'

'
Application.CommandBars.Add(Name:="Zoom").Visible = True
Application.CommandBars("Zoom").Controls.Add Type:=msoControlButton,
ID:= _
2949, Befo=1
Application.CommandBars("Zoom").Controls.Add Type:=msoControlButton,
ID:= _
2949, Befo=2
Application.CommandBars("Zoom").Controls.Add Type:=msoControlButton,
ID:= _
2949, Befo=3
Application.CommandBars("Zoom").Controls.Add Type:=msoControlButton,
ID:= _
2949, Befo=4
Application.CommandBars("Zoom").Controls.Add Type:=msoControlButton,
ID:= _
2949, Befo=5
End Sub

**************

How can I rename these buttons and link a macro to it - all in the same
code?? I want to put it into a autoopen, so I get this toolbar up which

is
used for the workbook and then I can also share the workbook with others

who
hasnt made this toolbar - of course I will delete it when I close the
workbook (autoclose). Is it also possible to let it the toolbar go up to

the
other toolbars (so its not just in the middle of everything)?

Rgds Lars







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
On custom toolbar, how to save macro link to flashdrive ? John Nelson Excel Discussion (Misc queries) 1 February 10th 09 10:49 PM
TOOLBAR FOR A MACRO FARAZ QURESHI Excel Discussion (Misc queries) 3 July 3rd 08 12:12 PM
macro in toolbar jatman Excel Discussion (Misc queries) 1 September 21st 06 08:25 AM
macro toolbar Ankur Excel Discussion (Misc queries) 3 August 5th 06 01:55 AM
Why does macros assigned to a toolbar lose its link when saved as Elsa Excel Discussion (Misc queries) 3 October 18th 05 09:48 PM


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