Save Button

G

Guest

Is there any way you can make the save and save as buttons
in excel password protected or hidden for a specific
spread sheet. I want to produce a template where users can
imput their results and excel will calculate the results
and let you print it off but not allow you to save it.
 
F

Frank Kabel

Hi
you can put the following code in your workbook module


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
cancel=true
End Sub
 
B

BrianB

Presumably you will want to save it. :cool:

This checks the network user name.


Code
-------------------

'=============================================
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'------------------------------------------
'-
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim UserName As String
'- Network Login Name
UserName = OSUserName
If UserName <> "SmithF" Then
MsgBox ("You cannot save this file")
Cancel = True
End If
End Sub
'-
'-----------------------------------
Function OSUserName() As String
'-----------------------------------
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
OSUserName = Left$(strUserName, lngLen - 1)
Else
OSUserName = vbNullString
End If
End Function
'==============================================
 
F

Frank Kabel

Hi
a different solution:
- enter this code
- in the VBA editor in the immediate window enter
application.enableevents=false
- save the file
- enter the statement
application.enableevents=True
 
Top