I created a plain text file DisableWord_SaveAs.bas containing the following text:
Code:
Sub FileSaveAs()
End Sub
Then ran the following code:-
Code:
Sub temp()
Dim wordApp As Object
Dim wordDoc As Object
Dim vbProj As VBProject
Dim vbComp As VBComponent
Dim vbMod As CodeModule
Set wordApp = CreateObject("Word.Application")
If wordApp Is Nothing Then
MsgBox "Could not start Microsioft Word.", vbCritical, "Error..."
End If
Set wordDoc = wordApp.Documents.Open("<Full Path To File>)
For Each vbProj In wordApp.Application.VBE.VBProjects
For Each vbComp In vbProj.VBComponents
If vbProj.Name = "Project" And vbComp.Name = "ThisDocument" Then
vbComp.CodeModule.AddFromFile ("DisableWord_SaveAs.bas")
Exit For
End If
Next vbComp
Next vbProj
wordDoc.Save
wordDoc.close
wordApp.Quit
Set wordDoc = Nothing
Set vbMod = Nothing
Set vbProj = Nothing
Set wordApp = Nothing
End Sub
The code above adds the text contained in the DisableWord_SaveAs.bas text file, to the "ThisDocument" code module under the "Project" node in the VBE - thus disabling the FileSaveAs command.
**** Note: For the above to work, the user must have granted access to the VBA Object under:
File | Options | Trust Centre | Trust Centre Settings... (button) | Macro Settings and tick "Trust access to the VBA object model".