Save Button

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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
'==============================================
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top