Consulting

Results 1 to 5 of 5

Thread: Solved: Quick Access Toolbar Word 2007

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    7
    Location

    Solved: Quick Access Toolbar Word 2007

    I am trying to prevent certain users from being able to do a "Save As". I have eliminated the option from the Office Menu. I have added Save As to the QAT, but have been unable to figure out how to either

    A) make it invisible to certian users
    B) disable and enable it through VBA


    Anyone with any ideas, please let me know

    Thanks

    Jason

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Probably easier to disable it via VBA for certain users than manipulate the UI. There are always keyboard shortcuts too.

    What is the scope here Jason? If controlling the save event for a file you can use a standard module along with a class module (there is no direct event exposed to the ThisDocument in the OM, unfortunately).

    In the VBE of your Word file:

    1. Insert a Class Module
    2. Rename your class module (I renamed mine as ThisApplication)
    3. In your class module paste the code below marked as such
    4. In a standard module (double click it) paste the code denoted below


    In your ThisApplication class module (or whatever you named it):
    [vba]Option Explicit

    Public WithEvents oApp As Word.Application

    Private Sub oApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    SaveAsUI = False
    MsgBox "You wanted to save? Hmmmmm...????"
    Cancel = True
    End Sub[/vba]

    In your standard module:
    [vba]Option Explicit

    Dim oAppClass As New ThisApplication 'NOTE: This MUST match your class module name!

    Public Sub AutoExec()
    Set oAppClass.oApp = Word.Application
    End Sub[/vba]

    Now you control the save events. Note you control ALL of the save events, so that Doc variable may become very important to you. You can also use the Environ("UserName") to get the current username of whoever is logged into the computer.

    Please post back if you need more help.
    Last edited by Zack Barresse; 06-06-2008 at 04:42 PM. Reason: Made less confusing..

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Way late on this, but I fully agree with Zack.

    Unless you use startFromScratch=true, you have no control over the QAT, so unless you're prepared to going the whole route, what Zack has proposed is the better way.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    VBAX Regular
    Joined
    Nov 2006
    Posts
    16
    Location
    A simple way to control this is might be to hijack the 'SaveAs' command by writing your own 'SaveAs' command and provide some filtering in the code as to who may complete the 'Save As' task. NOTE: Might come unstruck if there is a keyboard shortcut for the task.

    I believe this process is allowed by the word object model which will call VBA procedures of the same name in the following order:
    * document procedure
    * template procedure
    * global template procedure
    * normal.dot procedure
    Greg

  5. #5
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Greg's correct.

    You can 'hijack' an existing Word function, such as Save or SaveAs. When you do, you overwrite the default function. Here's an example:
    [VBA]Sub FileSave()
    MsgBox "Saving changes to the document is not allowed." & vbCrLf & vbCrLf _
    & "Please close the document when you are finished.", , "Action Canceled"
    End Sub
    Sub FileSaveAs()
    MsgBox "Saving changes to the document is not allowed." & vbCrLf & vbCrLf _
    & "Please close the document when you are finished.", , "Action Canceled"
    End Sub
    [/VBA]
    If a User tries to Save or use SaveAs they will get a message box (in my case), and that's all. This works for all methods of calling these functions- including menus, buttons, and hotkeys.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •