Airfix9
Well-known Member
- Joined
- Sep 23, 2005
- Messages
- 886
Hi MrExcel-land,
I have a file which needs the save functionality to be handled in a slightly strange way. To this end, I have written the following code:~
The problem occurs at the point indicated by the asterisks... the file does not save! It only happens when I use the close event (the file should save itself upon closing). Here is my code for the close event:~
Any help in explaining this would be gratefully received.
I have a file which needs the save functionality to be handled in a slightly strange way. To this end, I have written the following code:~
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = False Then
If Right(ThisWorkbook.Path, 3) = "zip" Then
Cancel = True
Else
Cancel = True
Application.EnableEvents = False
Me.Save '***********
Call AfterSave
Application.EnableEvents = True
End If
Else
Cancel = True
Application.EnableEvents = False
Dim FileSaveFullPath As String
Do
FileSaveFullPath = Application.GetSaveAsFilename("08 PSE Daily Figures (New).xls", _
, , "Please select a location to save the file")
Loop Until FileSaveFullPath <> "False"
ThisWorkbook.SaveAs (FileSaveFullPath)
Call AfterSave
Application.EnableEvents = True
End If
End Sub
The problem occurs at the point indicated by the asterisks... the file does not save! It only happens when I use the close event (the file should save itself upon closing). Here is my code for the close event:~
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
If CheckFileIsOpen(strData) = True Then
Set wb = Workbooks(strData)
wb.Windows(1).Visible = True
With Workbooks(strData)
.Saved = True
.Close
End With 'Workbooks(strDATA)
End If
ThisWorkbook.Sheets("Report").Visible = True
For i = 1 To Sheets.Count
Select Case Sheets(i).Tab.ColorIndex
Case 41
Sheets(i).Visible = True
Case 1
Sheets(i).Visible = xlHidden
Case Else
Sheets(i).Visible = xlVeryHidden
End Select
Next i
If Right(ThisWorkbook.Path, 3) = "zip" Then
ThisWorkbook.Saved = True
Else
ThisWorkbook.Save
End If
Application.ScreenUpdating = True
End Sub
Any help in explaining this would be gratefully received.