VB6 - Possible to disable the "Save As" in Word?

Associate
Joined
18 Oct 2002
Posts
231
I'm creating a new word object from VB6:

Code:
Dim oApp As Word.Application
Dim oDoc As Word.Document

Set oApp = CreateObject("Word.Application")
Set oDoc = oApp.Documents.Open(mobjSettings.PrecedentDir & sDocument, , True, False)

Is there any way that I can disable the 'Save As' in Word (i.e. the menu item)? I only want user's to save to the location of the original file if opened through my app.

Edit:
I've done a little testing in VBA and found:
Code:
Dim controlview As CommandBarControl
Set controlview = CommandBars.ActiveMenuBar.Controls.Item("File")
controlview.CommandBar.Controls("Save &As...").Delete
Does it! However it is permanent. Had to restore a backup of my normal.dot to get it back. I only want the option to not be used if working on a document opened through my app. This is all internal btw not for joe public.

The other alternative of course would be to catch the Save As event with a VBA macro and prevent it if a certain condition exists. I don't know if its possible to trap the event though with VBA.
 
Last edited:
Solved it through VBA:

Code:
Dim oAppClass As New ThisApplication

Sub AutoExec()
    Set oAppClass.oApp = Word.Application
End Sub

Then in a class module called ThisApplication:
Code:
Public WithEvents oApp As Word.Application

Private Sub oApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
Dim intResponse As Integer

    If LCase(oApp.Path)) = "\\server\thepaththatthesefilesarein" Then
        If SaveAsUI = True Then
            MsgBox "Save As Disabled", vbCritical, "'Save As' Warning"
            Cancel = True
        End If
    End If
End Sub
 
Back
Top Bottom