Solved

Office Toolbars

Posted on 2002-05-27
11
438 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office 2013 constant OST corruption 22 145
Surface Book vs Surface Pro 4 77
IT Desktop Support 11 74
ProperCase in Excel (Sheet) 3 13
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
My experience with Windows 10 over a one year period and suggestions for smooth operation
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

809 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