Solved

Office Toolbars

Posted on 2002-05-27
11
437 Views
Last Modified: 2006-11-17
Hello.

When I open an office document I want some toolbars to be disabled (this is for a template that I am trying to make). I use the following vba code but it does not even run. Can anyone help me?


--------------------------------------------------

Private Sub Document_DocumentOpened(ByVal doc As IVDocument)

Dim cbars As CommandBars
Dim cbar1 As CommandBar
Dim cbar2 As CommandBar

Set cbars = Application.CommandBars


Set cbar1 = cbars("Standard")
Set cbar2 = cbars("Formatting")

'Disable the command bars

cbar1.Enabled = False

cbar2.Enabled = False

End Sub
0
Comment
Question by:kkarnez
  • 5
  • 3
  • 3
11 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 7037176
Hi Kkarnez,

how are you calling this function?

Private Sub Document_DocumentOpened(ByVal doc As IVDocument)

End Sub

you've to call it in the open event of the thisdocument object

Private Sub Document_Open()
  call Sub Document_DocumentOpened(ActiveDocument)
End Sub

you could even do it like

Private Sub Document_Open()
Dim cbars As CommandBars
Dim cbar1 As CommandBar
Dim cbar2 As CommandBar

Set cbars = Application.CommandBars


Set cbar1 = cbars("Standard")
Set cbar2 = cbars("Formatting")

'Disable the command bars

cbar1.Enabled = False

cbar2.Enabled = False
End Sub


if you need any more help just leave the comments here and we're try to make it work

HTH:O)Bruintje
0
 

Author Comment

by:kkarnez
ID: 7037194
Hi.

It didn't work. I've put it under ThisDocument (general section).
Where should I put it?

-------------------

Private Sub Document_Open()

Dim cbars As CommandBars
Dim cbar1 As CommandBar
Dim cbar2 As CommandBar

Set cbars = Application.CommandBars


Set cbar1 = cbars("Standard")
Set cbar2 = cbars("Formatting")

'Disable the command bars

cbar1.Enabled = False

cbar2.Enabled = False
End Sub
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7037759
Hi Kkarnez,

you can download a sample document with this code in the open event

if you open it will first show a message box and then hide the bars

if it works then you can play a bit more with it, we;ve to make sure that cod eis running anyway

it could also be the settings in your word where no macros is checked check tools | macro | security it should be able to run at least macros

http://www.bredlum.com/ee_temp/commandbar.doc

HTH:O)Bruintje
0
 
LVL 2

Expert Comment

by:macbone2
ID: 7037895
Hi bruintje, being curious and a trusting idiot I clicked on your link. It disabled the command bars in Word, but also removed them from View | Toolbars. I got them back by running the macro with enabled = true. However, the appearance of my web browser has also been changed and I can't get back to how it was. Any suggestions?

macbone2
0
 
LVL 2

Expert Comment

by:macbone2
ID: 7037902
What I mean is I've got some of the toolbar icons, but they are all overlaid on top of each other at the top of the screen, and I can't drag them down. Help!!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:macbone2
ID: 7037904
Forget that. I've sorted it by toggling full screen off.
Sorry to waste your time.

ta  macbone2
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7038354
macbone2 > you're right about getting them back with enabled = true you can always add that on the document_close event so things will be restored on closing the template

glad i was sleeping through it because i wouldn't know why it had an effect on the browser :)
0
 

Author Comment

by:kkarnez
ID: 7038651
Hi.

Actually I dont use word but visio 2000.
The default function that does the same work like
Document_Open is :

Private Sub Document_DocumentOpened(ByVal doc As IVDocument)

There is no Document_Open !!.

Anyway, I've checked the sequrity and it is in medium which should cause no problem. Your example works fine by the way...
0
 
LVL 44

Accepted Solution

by:
bruintje earned 50 total points
ID: 7038663
hmm....forgot to ask what app you used visio is at home so i can make some intelligent comment later on, or hopefully someone with visio at hand will log on

:O)Bruintje
0
 

Author Comment

by:kkarnez
ID: 7038766
I found it!!

it just doesnt work if the file is a visio template and not a simple document... WHY???

Microsoft sucks!!

thanks for your help
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7038786
thanks and that's a good question i'll try to find that out later :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Perhaps more familiar to developers who primarily use VBScript than to developers who tend to work only with Microsoft Office and Visual Basic for Applications (VBA), the Dictionary is a powerful and versatile class, and is useful …
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now