ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File not saving (https://www.excelbanter.com/excel-programming/442789-file-not-saving.html)

Michelle

File not saving
 
I am trying to save another (differently named) version of my file whenever
I save.

It works fine if I use the normal save, but if the save is triggered from
the Before_Close event, it just skips over the following line...

ThisWorkbook.SaveAs Filename:=CurrPath & "\" & CurrName

in debug, it finds the line (it goes yellow), it doesn't generate any
errors, but it steps through the line without doing any saving

The CurrPath and CurrName variables do contain valid text

Why is it not saving?

thanks

M


Jacob Skaria

File not saving
 
Try

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
ThisWorkbook.SaveAs Filename:=CurrPath & "\" & CurrName
End Sub

--
Jacob (MVP - Excel)


"Michelle" wrote:

I am trying to save another (differently named) version of my file whenever
I save.

It works fine if I use the normal save, but if the save is triggered from
the Before_Close event, it just skips over the following line...

ThisWorkbook.SaveAs Filename:=CurrPath & "\" & CurrName

in debug, it finds the line (it goes yellow), it doesn't generate any
errors, but it steps through the line without doing any saving

The CurrPath and CurrName variables do contain valid text

Why is it not saving?

thanks

M


Jacob Skaria

File not saving
 
Oops...Disable the events and then save as..

Application.EnableEvents = False
ThisWorkbook.SaveAs Filename:=CurrPath & "\" & CurrName
Application.EnableEvents = True

--
Jacob (MVP - Excel)


"Jacob Skaria" wrote:

Try

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
ThisWorkbook.SaveAs Filename:=CurrPath & "\" & CurrName
End Sub

--
Jacob (MVP - Excel)


"Michelle" wrote:

I am trying to save another (differently named) version of my file whenever
I save.

It works fine if I use the normal save, but if the save is triggered from
the Before_Close event, it just skips over the following line...

ThisWorkbook.SaveAs Filename:=CurrPath & "\" & CurrName

in debug, it finds the line (it goes yellow), it doesn't generate any
errors, but it steps through the line without doing any saving

The CurrPath and CurrName variables do contain valid text

Why is it not saving?

thanks

M


Dave Peterson

File not saving
 
Take a look at VBA's help for .SaveCopyAs

It sounds like that may be more appropriate for you.

Michelle wrote:

I am trying to save another (differently named) version of my file whenever
I save.

It works fine if I use the normal save, but if the save is triggered from
the Before_Close event, it just skips over the following line...

ThisWorkbook.SaveAs Filename:=CurrPath & "\" & CurrName

in debug, it finds the line (it goes yellow), it doesn't generate any
errors, but it steps through the line without doing any saving

The CurrPath and CurrName variables do contain valid text

Why is it not saving?

thanks

M


--

Dave Peterson


All times are GMT +1. The time now is 04:40 PM.

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