Thread: VBA Save
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_3_] Bob Phillips[_3_] is offline
external usenet poster
 
Posts: 2,420
Default VBA Save


Use the BeforeSave event, make sure that you set Cancel = True

--
__________________________________
HTH

Bob

"terilad" wrote in message
...
Hi,

I have the following macro that saves as a filename when closed, how can I
also add to the code for the fil to save as when the save icon is clicked
as
well along with the close icon.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim strPath As String
Dim strFilename As String
Dim userResponse As Variant
strFilename = "Galashiels Resources WC " & Format(Sheets("Galashiels
Resources").Range("N2"), "dd-mmm-yy")
userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
vbDefaultButton2 + vbQuestion, "Galashiels Operational Resources © MN
")
If userResponse = vbYes Then
strPath = "C:\Users\Mark\Desktop"
strFilename = strPath & "\" & strFilename & ".xls"
ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
CreateBackup:=False
End If
End Sub

Many thanks

Mark