PC Review


Reply
 
 
terilad
Guest
Posts: n/a
 
      10th Jul 2009
Hi,

I need some more help with this code when msg box appears do you want to
save as etc I click yes thats fine it saves as the new filename, but when I
click No it is still saving changes in workbook to old filename, I need the
workbook to close without any changes made if No is selected in msg box, can
you help with this.

Here is the code:

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


Regards


Mark


 
Reply With Quote
 
 
 
 
john
Guest
Posts: n/a
 
      10th Jul 2009
see if this does what you want?


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strPath As String
Dim strFilename As String
Dim userResponse As Variant

Application.EnableEvents = False

strFilename = "Kelso Resources WC " & _
Format(Sheets("KelsoResources").Range("N2"), "dd-mmm-yy")

userResponse = MsgBox("Do you want to save as " & _
strFilename, vbYesNo + vbInformation, _
"Kelso Operational Resources © MN ")

If userResponse = vbYes Then

strPath = "C:\Users\Mark\Desktop"

strFilename = strPath & "\" & strFilename & ".xls"

ThisWorkbook.SaveAs Filename:=strFilename, _
FileFormat:=xlNormal, _
CreateBackup:=False

Cancel = False

Else

Cancel = True

End If

Application.EnableEvents = True

End Sub

--
jb


"terilad" wrote:

> Hi,
>
> I need some more help with this code when msg box appears do you want to
> save as etc I click yes thats fine it saves as the new filename, but when I
> click No it is still saving changes in workbook to old filename, I need the
> workbook to close without any changes made if No is selected in msg box, can
> you help with this.
>
> Here is the code:
>
> End Sub
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> Dim strPath As String
> Dim strFilename As String
> Dim userResponse As Variant
> Application.EnableEvents = False
> strFilename = "Kelso Resources WC " & Format(Sheets("Kelso
> Resources").Range("N2"), "dd-mmm-yy")
> userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> vbInformation, "Kelso Operational Resources © MN ")
> If userResponse = vbYes Then
> strPath = "C:\Users\Mark\Desktop"
> strFilename = strPath & "\" & strFilename & ".xls"
> ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
> CreateBackup:=False
> Cancel = False
> End If
> Application.EnableEvents = False
> End Sub
>
>
> Regards
>
>
> Mark
>
>

 
Reply With Quote
 
terilad
Guest
Posts: n/a
 
      10th Jul 2009
This code has caused Microsoft excel to stop working when I click save as new
filename.

Mark

"john" wrote:

> see if this does what you want?
>
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> Dim strPath As String
> Dim strFilename As String
> Dim userResponse As Variant
>
> Application.EnableEvents = False
>
> strFilename = "Kelso Resources WC " & _
> Format(Sheets("KelsoResources").Range("N2"), "dd-mmm-yy")
>
> userResponse = MsgBox("Do you want to save as " & _
> strFilename, vbYesNo + vbInformation, _
> "Kelso Operational Resources © MN ")
>
> If userResponse = vbYes Then
>
> strPath = "C:\Users\Mark\Desktop"
>
> strFilename = strPath & "\" & strFilename & ".xls"
>
> ThisWorkbook.SaveAs Filename:=strFilename, _
> FileFormat:=xlNormal, _
> CreateBackup:=False
>
> Cancel = False
>
> Else
>
> Cancel = True
>
> End If
>
> Application.EnableEvents = True
>
> End Sub
>
> --
> jb
>
>
> "terilad" wrote:
>
> > Hi,
> >
> > I need some more help with this code when msg box appears do you want to
> > save as etc I click yes thats fine it saves as the new filename, but when I
> > click No it is still saving changes in workbook to old filename, I need the
> > workbook to close without any changes made if No is selected in msg box, can
> > you help with this.
> >
> > Here is the code:
> >
> > End Sub
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > Dim strPath As String
> > Dim strFilename As String
> > Dim userResponse As Variant
> > Application.EnableEvents = False
> > strFilename = "Kelso Resources WC " & Format(Sheets("Kelso
> > Resources").Range("N2"), "dd-mmm-yy")
> > userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> > vbInformation, "Kelso Operational Resources © MN ")
> > If userResponse = vbYes Then
> > strPath = "C:\Users\Mark\Desktop"
> > strFilename = strPath & "\" & strFilename & ".xls"
> > ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
> > CreateBackup:=False
> > Cancel = False
> > End If
> > Application.EnableEvents = False
> > End Sub
> >
> >
> > Regards
> >
> >
> > Mark
> >
> >

 
Reply With Quote
 
john
Guest
Posts: n/a
 
      10th Jul 2009
sorry, did not fully read your post - you want the file to close without
saving changes when NO press?

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strPath As String
Dim strFilename As String
Dim userResponse As Variant

Application.EnableEvents = False

strFilename = "Kelso Resources WC " & _
Format(Sheets("KelsoResources").Range("N2"), "dd-mmm-yy")

userResponse = MsgBox("Do you want to save as " & _
strFilename, vbYesNo + vbInformation, _
"Kelso Operational Resources © MN ")

If userResponse = vbYes Then

strPath = "C:\Users\Mark\Desktop"

strFilename = strPath & "\" & strFilename & ".xls"

ThisWorkbook.SaveAs Filename:=strFilename, _
FileFormat:=xlNormal, _
CreateBackup:=False

Cancel = False

Else

Cancel = True

Application.EnableEvents = True

ThisWorkbook.Close False

End If

Application.EnableEvents = True

End Sub

--
jb


"terilad" wrote:

> Hi,
>
> I need some more help with this code when msg box appears do you want to
> save as etc I click yes thats fine it saves as the new filename, but when I
> click No it is still saving changes in workbook to old filename, I need the
> workbook to close without any changes made if No is selected in msg box, can
> you help with this.
>
> Here is the code:
>
> End Sub
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> Dim strPath As String
> Dim strFilename As String
> Dim userResponse As Variant
> Application.EnableEvents = False
> strFilename = "Kelso Resources WC " & Format(Sheets("Kelso
> Resources").Range("N2"), "dd-mmm-yy")
> userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> vbInformation, "Kelso Operational Resources © MN ")
> If userResponse = vbYes Then
> strPath = "C:\Users\Mark\Desktop"
> strFilename = strPath & "\" & strFilename & ".xls"
> ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
> CreateBackup:=False
> Cancel = False
> End If
> Application.EnableEvents = False
> End Sub
>
>
> Regards
>
>
> Mark
>
>

 
Reply With Quote
 
john
Guest
Posts: n/a
 
      10th Jul 2009

How do you mean stop working?

Only change I suggested was to add

Else

Cancel = True

in your If statement.


--
jb


"terilad" wrote:

> This code has caused Microsoft excel to stop working when I click save as new
> filename.
>
> Mark
>
> "john" wrote:
>
> > see if this does what you want?
> >
> >
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > Dim strPath As String
> > Dim strFilename As String
> > Dim userResponse As Variant
> >
> > Application.EnableEvents = False
> >
> > strFilename = "Kelso Resources WC " & _
> > Format(Sheets("KelsoResources").Range("N2"), "dd-mmm-yy")
> >
> > userResponse = MsgBox("Do you want to save as " & _
> > strFilename, vbYesNo + vbInformation, _
> > "Kelso Operational Resources © MN ")
> >
> > If userResponse = vbYes Then
> >
> > strPath = "C:\Users\Mark\Desktop"
> >
> > strFilename = strPath & "\" & strFilename & ".xls"
> >
> > ThisWorkbook.SaveAs Filename:=strFilename, _
> > FileFormat:=xlNormal, _
> > CreateBackup:=False
> >
> > Cancel = False
> >
> > Else
> >
> > Cancel = True
> >
> > End If
> >
> > Application.EnableEvents = True
> >
> > End Sub
> >
> > --
> > jb
> >
> >
> > "terilad" wrote:
> >
> > > Hi,
> > >
> > > I need some more help with this code when msg box appears do you want to
> > > save as etc I click yes thats fine it saves as the new filename, but when I
> > > click No it is still saving changes in workbook to old filename, I need the
> > > workbook to close without any changes made if No is selected in msg box, can
> > > you help with this.
> > >
> > > Here is the code:
> > >
> > > End Sub
> > > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > > Dim strPath As String
> > > Dim strFilename As String
> > > Dim userResponse As Variant
> > > Application.EnableEvents = False
> > > strFilename = "Kelso Resources WC " & Format(Sheets("Kelso
> > > Resources").Range("N2"), "dd-mmm-yy")
> > > userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> > > vbInformation, "Kelso Operational Resources © MN ")
> > > If userResponse = vbYes Then
> > > strPath = "C:\Users\Mark\Desktop"
> > > strFilename = strPath & "\" & strFilename & ".xls"
> > > ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
> > > CreateBackup:=False
> > > Cancel = False
> > > End If
> > > Application.EnableEvents = False
> > > End Sub
> > >
> > >
> > > Regards
> > >
> > >
> > > Mark
> > >
> > >

 
Reply With Quote
 
terilad
Guest
Posts: n/a
 
      10th Jul 2009
This code is still causing excel to stop working when selected yes to saveas
new filename, I think it may have something to do with trying to recover
workbook, as it is being saved as a new name.

Any ideas how to resolve this issue

Mark

"john" wrote:

> sorry, did not fully read your post - you want the file to close without
> saving changes when NO press?
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> Dim strPath As String
> Dim strFilename As String
> Dim userResponse As Variant
>
> Application.EnableEvents = False
>
> strFilename = "Kelso Resources WC " & _
> Format(Sheets("KelsoResources").Range("N2"), "dd-mmm-yy")
>
> userResponse = MsgBox("Do you want to save as " & _
> strFilename, vbYesNo + vbInformation, _
> "Kelso Operational Resources © MN ")
>
> If userResponse = vbYes Then
>
> strPath = "C:\Users\Mark\Desktop"
>
> strFilename = strPath & "\" & strFilename & ".xls"
>
> ThisWorkbook.SaveAs Filename:=strFilename, _
> FileFormat:=xlNormal, _
> CreateBackup:=False
>
> Cancel = False
>
> Else
>
> Cancel = True
>
> Application.EnableEvents = True
>
> ThisWorkbook.Close False
>
> End If
>
> Application.EnableEvents = True
>
> End Sub
>
> --
> jb
>
>
> "terilad" wrote:
>
> > Hi,
> >
> > I need some more help with this code when msg box appears do you want to
> > save as etc I click yes thats fine it saves as the new filename, but when I
> > click No it is still saving changes in workbook to old filename, I need the
> > workbook to close without any changes made if No is selected in msg box, can
> > you help with this.
> >
> > Here is the code:
> >
> > End Sub
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > Dim strPath As String
> > Dim strFilename As String
> > Dim userResponse As Variant
> > Application.EnableEvents = False
> > strFilename = "Kelso Resources WC " & Format(Sheets("Kelso
> > Resources").Range("N2"), "dd-mmm-yy")
> > userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> > vbInformation, "Kelso Operational Resources © MN ")
> > If userResponse = vbYes Then
> > strPath = "C:\Users\Mark\Desktop"
> > strFilename = strPath & "\" & strFilename & ".xls"
> > ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
> > CreateBackup:=False
> > Cancel = False
> > End If
> > Application.EnableEvents = False
> > End Sub
> >
> >
> > Regards
> >
> >
> > Mark
> >
> >

 
Reply With Quote
 
terilad
Guest
Posts: n/a
 
      10th Jul 2009
Excel is obviously creating a backup because of this code as when I open the
new workbook that has saved with new filename it is also opening previous
workbook as backup.

Any ideas how to resolve.

Mark

"john" wrote:

> sorry, did not fully read your post - you want the file to close without
> saving changes when NO press?
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> Dim strPath As String
> Dim strFilename As String
> Dim userResponse As Variant
>
> Application.EnableEvents = False
>
> strFilename = "Kelso Resources WC " & _
> Format(Sheets("KelsoResources").Range("N2"), "dd-mmm-yy")
>
> userResponse = MsgBox("Do you want to save as " & _
> strFilename, vbYesNo + vbInformation, _
> "Kelso Operational Resources © MN ")
>
> If userResponse = vbYes Then
>
> strPath = "C:\Users\Mark\Desktop"
>
> strFilename = strPath & "\" & strFilename & ".xls"
>
> ThisWorkbook.SaveAs Filename:=strFilename, _
> FileFormat:=xlNormal, _
> CreateBackup:=False
>
> Cancel = False
>
> Else
>
> Cancel = True
>
> Application.EnableEvents = True
>
> ThisWorkbook.Close False
>
> End If
>
> Application.EnableEvents = True
>
> End Sub
>
> --
> jb
>
>
> "terilad" wrote:
>
> > Hi,
> >
> > I need some more help with this code when msg box appears do you want to
> > save as etc I click yes thats fine it saves as the new filename, but when I
> > click No it is still saving changes in workbook to old filename, I need the
> > workbook to close without any changes made if No is selected in msg box, can
> > you help with this.
> >
> > Here is the code:
> >
> > End Sub
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > Dim strPath As String
> > Dim strFilename As String
> > Dim userResponse As Variant
> > Application.EnableEvents = False
> > strFilename = "Kelso Resources WC " & Format(Sheets("Kelso
> > Resources").Range("N2"), "dd-mmm-yy")
> > userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> > vbInformation, "Kelso Operational Resources © MN ")
> > If userResponse = vbYes Then
> > strPath = "C:\Users\Mark\Desktop"
> > strFilename = strPath & "\" & strFilename & ".xls"
> > ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
> > CreateBackup:=False
> > Cancel = False
> > End If
> > Application.EnableEvents = False
> > End Sub
> >
> >
> > Regards
> >
> >
> > Mark
> >
> >

 
Reply With Quote
 
terilad
Guest
Posts: n/a
 
      10th Jul 2009
Fixed it, changed the cancel = true and false round and works

"john" wrote:

> sorry, did not fully read your post - you want the file to close without
> saving changes when NO press?
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> Dim strPath As String
> Dim strFilename As String
> Dim userResponse As Variant
>
> Application.EnableEvents = False
>
> strFilename = "Kelso Resources WC " & _
> Format(Sheets("KelsoResources").Range("N2"), "dd-mmm-yy")
>
> userResponse = MsgBox("Do you want to save as " & _
> strFilename, vbYesNo + vbInformation, _
> "Kelso Operational Resources © MN ")
>
> If userResponse = vbYes Then
>
> strPath = "C:\Users\Mark\Desktop"
>
> strFilename = strPath & "\" & strFilename & ".xls"
>
> ThisWorkbook.SaveAs Filename:=strFilename, _
> FileFormat:=xlNormal, _
> CreateBackup:=False
>
> Cancel = False
>
> Else
>
> Cancel = True
>
> Application.EnableEvents = True
>
> ThisWorkbook.Close False
>
> End If
>
> Application.EnableEvents = True
>
> End Sub
>
> --
> jb
>
>
> "terilad" wrote:
>
> > Hi,
> >
> > I need some more help with this code when msg box appears do you want to
> > save as etc I click yes thats fine it saves as the new filename, but when I
> > click No it is still saving changes in workbook to old filename, I need the
> > workbook to close without any changes made if No is selected in msg box, can
> > you help with this.
> >
> > Here is the code:
> >
> > End Sub
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
> > Dim strPath As String
> > Dim strFilename As String
> > Dim userResponse As Variant
> > Application.EnableEvents = False
> > strFilename = "Kelso Resources WC " & Format(Sheets("Kelso
> > Resources").Range("N2"), "dd-mmm-yy")
> > userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> > vbInformation, "Kelso Operational Resources © MN ")
> > If userResponse = vbYes Then
> > strPath = "C:\Users\Mark\Desktop"
> > strFilename = strPath & "\" & strFilename & ".xls"
> > ThisWorkbook.SaveAs Filename:=strFilename, FileFormat:=xlNormal,
> > CreateBackup:=False
> > Cancel = False
> > End If
> > Application.EnableEvents = False
> > End Sub
> >
> >
> > Regards
> >
> >
> > Mark
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
beforesave Doug Microsoft Excel Programming 4 11th Jun 2009 07:56 PM
Re: beforesave Patrick Molloy Microsoft Excel Programming 0 11th Jun 2009 06:53 PM
BeforeSave =?Utf-8?B?U3RldmVu?= Microsoft Excel Programming 2 21st Jan 2006 05:37 PM
BeforeSave Sub Phil Hageman Microsoft Excel Programming 6 14th Jan 2004 10:12 AM
VBA - BeforeSave - NEED HELP HRobertson Microsoft Excel Programming 2 23rd Oct 2003 06:50 PM


Features
 

Advertising
 

Newsgroups
 


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