I am using the following code which creates a toolbar button on excel menu. On button click it executes a macro
Private Sub Command1_Click()
' Start Word
Dim wdapp As Object 'Excel.Application
Set wdapp = CreateObject("Word.Application")
' Make it visible...
wdapp.Visible = True
' Add a new workbook
Dim xlbook As Object 'Excel.Workbook
Set xlbook = xlapp.Workbooks.Add
' Add a module
Dim xlmodule As Object 'VBComponent
Set xlmodule = xlbook.VBProject.VBComponents.Add(1) 'vbext_ct_StdModule
' Add a macro to the module...
Dim strCode As String
strCode = _
"sub MyMacro()" & vbCr & _
" msgbox ""Inside generated macro!!!"" " & vbCr & _
"end sub"
xlmodule.CodeModule.AddFromString strCode
' Run the new macro!
xlapp.Run "MyMacro"
' ** Create a new toolbar with a button to fire macro...
' Add a new toolbar...
Dim cbs As Object 'CommandBars
Dim cb As Object 'CommandBar
Set cbs = xlapp.CommandBars
Set cb = cbs.Add("MyCommandBar", 1, , True) '1=msoBarTop
cb.Visible = True
' Make it visible & add a button...
Dim cbc As Object 'CommandBarControl
Set cbc = cb.Controls.Add(1) '1=msoControlButton
' Assign our button to our macro
cbc.OnAction = "MyMacro"
' Set text...
cbc.caption = "Call MyMacro()"
' Set Face image...
' 51 = white hand
' 25 = glasses
' 34 = ink dipper
' etc...
cbc.faceId = 51
' Pause so you can inspect results...
MsgBox "All done, click me to continue...", vbMsgBoxSetForeground
' Remember to release module
Set xlmodule = Nothing
' Clean up
xlbook.Saved = True
xlapp.Quit
End Sub
But I want code which helps me in word document to create a toolbar button and runs a macro on click
thanks in advance