I setup a vb that disables the save as on the file menu.
the code works as expected. But only if I click on run in the VB editor.
In general I have
sub
command saveas enable=false (not exact syntax )
end sub
How do I get this to execute when I open the workbook?
When I close the workbook I want to reverse the code so that the next
workbookthat is opened does not have saveas greyed.
I have the code, but where to put it, so that it executes, is my problem.
Rick Rothstein (MVP - VB) - 02 Jun 2007 17:51 GMT
>I setup a vb that disables the save as on the file menu.
> the code works as expected. But only if I click on run in the VB editor.
[quoted text clipped - 8 lines]
>
> I have the code, but where to put it, so that it executes, is my problem.
I'm not sure about this, but in the VB editor, double-click the ThisWorkbook
item in the VBA Project Explorer tree (hit Ctrl+R if it is not showing) and
select Workbook from the left-hand drop down on the code editing window that
appears. In the right-hand drop down, select the Open event. Put your call
to you subroutine there. Now, save the project and close the workbook. Now,
when you reopen it, I THINK the SaveAs option will be disabled.
Rick
Bob Phillips - 02 Jun 2007 19:29 GMT
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Worksheet Menu
Bar").Controls("File").Controls("Save As...").Enabled = True
End Sub
Private Sub Workbook_Open()
Application.CommandBars("Worksheet Menu
Bar").Controls("File").Controls("Save As...").Enabled = False
End Sub
'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code

Signature
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)
>I setup a vb that disables the save as on the file menu.
> the code works as expected. But only if I click on run in the VB editor.
[quoted text clipped - 8 lines]
>
> I have the code, but where to put it, so that it executes, is my problem.
Bernie Deitrick - 02 Jun 2007 21:14 GMT
Will,
Better would be to use the before save event. Put this into the codemodule
of the ThisWorkbook object:
Private Sub Workbook_BeforeSave( _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
Msgbox "Sorry, you can only save me with my original name and path."
Cancel = True
End If
End Sub
HTH,
Bernie
MS Excel MVP
>I setup a vb that disables the save as on the file menu.
> the code works as expected. But only if I click on run in the VB editor.
[quoted text clipped - 8 lines]
>
> I have the code, but where to put it, so that it executes, is my problem.
Bob Flanagan - 03 Jun 2007 01:00 GMT
If the user disables macros when they open the workbook, they can do
whatever they want.
Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
>I setup a vb that disables the save as on the file menu.
> the code works as expected. But only if I click on run in the VB editor.
[quoted text clipped - 8 lines]
>
> I have the code, but where to put it, so that it executes, is my problem.
Will Sellers - 03 Jun 2007 04:26 GMT
Thanks guys
Your pointers worked like a charm
>I setup a vb that disables the save as on the file menu.
> the code works as expected. But only if I click on run in the VB editor.
[quoted text clipped - 8 lines]
>
> I have the code, but where to put it, so that it executes, is my problem.