ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SaveAs doesn't work (https://www.excelbanter.com/excel-programming/323141-saveas-doesnt-work.html)

broogle

SaveAs doesn't work
 
Excel Guru, please help!

I try to create a code when user save the workbook, the file name will
be taken from cell C10 & C7. It works fine with save button, but if I
select File-Save as, the code will run twice, if I disable the
enableevents it will disactivate another code in other sheets. Thanks

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

filesavename = Application.GetSaveAsFilename(Sheet1.Range("C10") &
Sheet1.Range("C7"), fileFilter:="Microsoft Excel Workbook (*.xls),
*.xls")

If filesavename < False Then

Else
Cancel = True
End If
end sub


Tom Ogilvy

SaveAs doesn't work
 
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)

filesavename = Application.GetSaveAsFilename( _
Sheet1.Range("C10") & Sheet1.Range("C7"), _
fileFilter:="Microsoft Excel Workbook (*.xls),*.xls")

If filesavename < False Then
Application.EnableEvents = False
if lcase(thisworkbook.fullname) = lcase(filesavename) then
thisworkbook.Save
else
on Error resume Next
kill filesavename
on Error goto 0
thisworkbook.SaveAs filesavename
end if
End If
Application.EnableEvents = True
Cancel = True
end sub

--
Regards,
Tom Ogilvy

"broogle" wrote in message
ups.com...
Excel Guru, please help!

I try to create a code when user save the workbook, the file name will
be taken from cell C10 & C7. It works fine with save button, but if I
select File-Save as, the code will run twice, if I disable the
enableevents it will disactivate another code in other sheets. Thanks

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

filesavename = Application.GetSaveAsFilename(Sheet1.Range("C10") &
Sheet1.Range("C7"), fileFilter:="Microsoft Excel Workbook (*.xls),
*.xls")

If filesavename < False Then

Else
Cancel = True
End If
end sub





All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com