LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
SU SU is offline
external usenet poster
 
Posts: 25
Default Automatic Filesave using Loginname

I have a spreadsheet where the users input their loginname and the file is
saved automatically using the loginname. Everything seems to work fine except
that when I save the file through Filesave command both prompts (see below)
keeps on appearing in a loop.

Please suggest a solution. Many thanks in advance.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'
Dim Response, MyString, Msg, Style, Title, Help, Ctxt
Dim MyFileName As String
Const SaveSheet As String = "Jan"
Const SaveCell As String = "X24"
Dim wb As Workbook
Set wb = ActiveWorkbook
'
'Cancel Save event
Cancel = True
'
'Create string variable for file name
Dim strFName As String
'Set file path in string
strFName = Sheets("Jan").Range("X24").Value
' Check if T23 - LoginName is empty
If wb.Worksheets("Jan").Range("T23") < "" Then
'If not, then verify LoginName
If MsgBox("Your LoginName is (" & Sheets("Jan").Range("T23").Value &
")," & _
vbCrLf & " and Your Name is (" & Sheets("Jan").Range("K23").Value & "),
" & _
vbCrLf & " Is this Correct?", vbYesNo, "Save Prompt") = vbYes Then
'If name is correct, Save file
Application.DisplayAlerts = False
Application.EnableEvents = False
wb.SaveAs strFName
Application.EnableEvents = True
Application.DisplayAlerts = True
Else
'If LoginName is NOT correct, prompt to change it
MsgBox "Please enter CORRECT LoginName in Cell T23 of Sheet Jan"
End If
Else
'Prompt for LoginName
MsgBox "You have not entered your LoginName" & vbCrLf & _
"on the first sheet (" & SaveSheet & "), in cell (T23)"
End If
End Sub
'
'
Sub Savefile()
'
Dim Response, MyString, Msg, Style, Title, Help, Ctxt
Dim MyFileName As String
Const SaveSheet As String = "Jan"
Const SaveCell As String = "X24"
Dim wb As Workbook
Set wb = ActiveWorkbook
'
'Cancel Save event
Cancel = True
'
'Create string variable for file name
Dim strFName As String
'Set file path in string
strFName = Sheets("Jan").Range("X24").Value
' Check if T23 - LoginName is empty
If wb.Worksheets("Jan").Range("T23") < "" Then
'If not, then verify LoginName
If MsgBox("Your LoginName is (" & Sheets("Jan").Range("T23").Value &
")," & _
vbCrLf & " and Your Name is (" & Sheets("Jan").Range("K23").Value & "),
" & _
vbCrLf & " Is this Correct?", vbYesNo, "Save Prompt") = vbYes Then
'If name is correct, Save file
Application.DisplayAlerts = False
Application.EnableEvents = False
wb.SaveAs strFName
Application.EnableEvents = True
Application.DisplayAlerts = True
Else
'If LoginName is NOT correct, prompt to change it
MsgBox "Please enter CORRECT LoginName in Cell T23 of Sheet Jan"
End If
Else
'Prompt for LoginName
MsgBox "You have not entered your LoginName" & vbCrLf & _
"on the first sheet (" & SaveSheet & "), in cell (T23)"
End If
End Sub
'
'
Private Sub Workbook_Open()

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
automatic [email protected] uk Excel Discussion (Misc queries) 1 June 20th 09 07:19 PM
Automatic update of spreadsheet & automatic update between workboo Losva Excel Worksheet Functions 6 September 12th 08 03:22 PM
Automatic Value Dave Excel Discussion (Misc queries) 1 December 11th 06 09:51 PM
Macro to Cut/PasteSpecial/FileSave tdbab Excel Programming 7 July 31st 06 01:42 PM
automatic row Ralph Excel Programming 1 February 28th 05 04:48 PM


All times are GMT +1. The time now is 11:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"