Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removal of CommandBar from Word, nested in IE

Status
Not open for further replies.

Nightsoft

Programmer
Aug 23, 2001
50
0
0
DK
Hi EveryOne.

I'm Really getting grey hair over this one...
I have a word document, which has a create commandbar function to make my own commandbar, when this particular document is opened.
It works okay, when opened localy. And it also gets removed when I close the word document.
But If I open the Word document in IE6.0 It won't show.
It runs the code, and the commandbar is also created.
Because when I open my word after closing the IE(Word dok),
The commandBar is there.
I made some msgbox's that tells me if it's allready installed, or if it has to make a new one.
And when opened in IE. I get the correct messages, as when looking at it "locally". But the commandbar just dosn't show...

Another funny thing, is, when I End my IE(Work dok) it tells me that the commandbar is removed. But It isn't?

Anyone know why IE Dosn't allow me to show the commandbars?
The Code is rather simple :
Code:
Public Sub MakeCommandBar()
  Dim cbcMyBar As Office.CommandBar
  Dim btnMyButton As Office.CommandBarButton
  ' Test to see if commandbar exists
  For Each cbcMyBar In Word.CommandBars
    If cbcMyBar.Name = "Dahls Lejekontrakt" Then
      CBarInstalled = True
      GoTo SubNext
    Else
      CBarInstalled = False
    End If
  Next
SubNext:

  On Error GoTo CreateBar_Err
  ' If commandbar exists then make it visible
  If CBarInstalled = True Then
    Word.CommandBars("Dahls Lejekontrakt").Visible = True
    MsgBox ("Found CommandBar")
  Else ' create bar
     MsgBox ("Making CommmandBar")
     Set cbcMyBar = Word.CommandBars.Add(Name:="Dahls Lejekontrakt")
     cbcMyBar.Protection = msoBarNoProtection
    
     ' Specify the commandbar button
     Set btnMyButton = cbcMyBar.Controls.Add(Type:=msoControlButton, Parameter:="StartDahls")
     With btnMyButton
       .Style = msoButtonCaption
       .BeginGroup = True
       .Caption = "&Dahls Lejekontrakt"
       .OnAction = "Functions.StartKontraktApp"
     End With

     cbcMyBar.Visible = True
   End If
   Exit Sub

CreateBar_Err:
   MsgBox Err.Number & vbCrLf & Err.Description
End Sub

My Code for deleting the commandbar is just
Code:
Word.CommandBars("Dahls Lejekontrakt").Delete

The thing that I'm most weirded out about, is that it does, make the commandbar, but dosn't show it... And
It does run the code to remove the commandbar, but it dosn't get removed.
It took me some time, just to get it removed in when viewed locally through word. Found out that Protection should be set to msoBarNoProtection

Machine code Rocks:)
 
I'm sure you've probably already tried this, but don't you have to click the "Tools" icon in IE?

Just a thought.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top