L
Lokutus
Hi,
I have created a new button in CommandBar:
Sub CreateButton()
Dim nBtn As Office.CommandBarButton
Dim cBar As Office.CommandBar
Dim BtnExists As Boolean
Dim Pos As Integer
Dim i As Integer
On Error GoTo eh
Set cBar = Application.CommandBars("File")
Let BtnExists = False
For i = 1 To cBar.Controls.Count
If cBar.Controls(i).Caption = "MyButton" Then
Let BtnExists = True
End If
If cBar.Controls(i).Caption = "Save &As..." Then
Let Pos = i + 1
End If
Next
If BtnExists Then
Set nBtn = cBar.Controls("MyButton")
Else
Set nBtn = cBar.Controls.Add(msoControlButton)
Let nBtn.Caption = "MyButton"
End If
Call nBtn.Move(Before:=Pos)
Let nBtn.OnAction = "RunAPI"
Exit Sub
eh:
MsgBox ("Error " & CStr(Err.Number) & ": " & Error)
End Sub
Then I need to erase that button while closing document. I tried either
to reset CommandBar (cBar.Reset) or call Delete method (Call
nBtn.Delete(False)) on that button. Works fine, but only for current
session. After that, when I open Word, button is still there.
Any suggestion? I need to erase the button permanently.
Thanks in advance. Jiri
I have created a new button in CommandBar:
Sub CreateButton()
Dim nBtn As Office.CommandBarButton
Dim cBar As Office.CommandBar
Dim BtnExists As Boolean
Dim Pos As Integer
Dim i As Integer
On Error GoTo eh
Set cBar = Application.CommandBars("File")
Let BtnExists = False
For i = 1 To cBar.Controls.Count
If cBar.Controls(i).Caption = "MyButton" Then
Let BtnExists = True
End If
If cBar.Controls(i).Caption = "Save &As..." Then
Let Pos = i + 1
End If
Next
If BtnExists Then
Set nBtn = cBar.Controls("MyButton")
Else
Set nBtn = cBar.Controls.Add(msoControlButton)
Let nBtn.Caption = "MyButton"
End If
Call nBtn.Move(Before:=Pos)
Let nBtn.OnAction = "RunAPI"
Exit Sub
eh:
MsgBox ("Error " & CStr(Err.Number) & ": " & Error)
End Sub
Then I need to erase that button while closing document. I tried either
to reset CommandBar (cBar.Reset) or call Delete method (Call
nBtn.Delete(False)) on that button. Works fine, but only for current
session. After that, when I open Word, button is still there.
Any suggestion? I need to erase the button permanently.
Thanks in advance. Jiri