Solved

Office Toolbars

Posted on 2002-05-27
11
434 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:macbone2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks and that's a good question i'll try to find that out later :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

772 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

11 Experts available now in Live!

Get 1:1 Help Now