Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

CreateButton - EraseButton

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lokutus - 17 Aug 2005 14:19 GMT
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
Chuck Henrich - 17 Aug 2005 15:51 GMT
Add the customization context:

[snip]
On Error GoTo eh
CustomizationContext = ActiveDocument
[snip]
Signature

Chuck Henrich
www.ProductivityApps.com

> Hi,
> I have created a new button in CommandBar:
[quoted text clipped - 41 lines]
>
> Thanks in advance. Jiri
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.