PC Review


Reply
Thread Tools Rate Thread

BeforeSave Event

 
 
terilad
Guest
Posts: n/a
 
      10th Jul 2009

Hi,

I have a code below and have a little problem with it, its not running
smoothly for me.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, 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 +
vbCritical, "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

Before save event, when I click on save it pops up the msg box do you want
to save as, when I click yes it pops up again and excel stops working, do you
have any ideas if my code is wrong.

Regards


Mark

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

Excellant many thanks.

Regards

Mark

"Jacob Skaria" wrote:

> Try the below code....Please note the changes Application.EnableEvents =
> True/False and 'Cacel =True'
>
>
> 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 = "Galashiels Resources WC " & Format(Sheets("Galashiels
> Resources").Range("N2"), "dd-mmm-yy")
> userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> vbCritical, "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
> Cancel = True
> End If
> Application.EnableEvents = True
>
> End Sub
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "terilad" wrote:
>
> > Hi,
> >
> > I have a code below and have a little problem with it, its not running
> > smoothly for me.
> >
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, 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 +
> > vbCritical, "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
> >
> > Before save event, when I click on save it pops up the msg box do you want
> > to save as, when I click yes it pops up again and excel stops working, do you
> > have any ideas if my code is wrong.
> >
> > Regards
> >
> >
> > Mark
> >

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

You didn't like yesterday's suggestions?

terilad wrote:
>
> Hi,
>
> I have a code below and have a little problem with it, its not running
> smoothly for me.
>
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, 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 +
> vbCritical, "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
>
> Before save event, when I click on save it pops up the msg box do you want
> to save as, when I click yes it pops up again and excel stops working, do you
> have any ideas if my code is wrong.
>
> Regards
>
> Mark


--

Dave Peterson
 
Reply With Quote
 
terilad
Guest
Posts: n/a
 
      10th Jul 2009

Hi Dave,

I couldn't get yesterdays solutions or codes to work as stated in todays
discussion, and I was looking for help to revise my code as I was having
problems with 2 pop up boxes and excel stopping. I did rate your answers on
the 8th with your 2 responses and altered my code accordingly as Sheet1 had a
different name and my file path was missing an s from user, so your responses
to my questions were of great help, code only needed additional slight
modification to resolve the issues with 2 pop up boxes and excel stopping. I
am learning slowly with VBA. Thankyou again for your input, all help is
greatfully appreciated.

Thanks

"Dave Peterson" wrote:

> You didn't like yesterday's suggestions?
>
> terilad wrote:
> >
> > Hi,
> >
> > I have a code below and have a little problem with it, its not running
> > smoothly for me.
> >
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, 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 +
> > vbCritical, "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
> >
> > Before save event, when I click on save it pops up the msg box do you want
> > to save as, when I click yes it pops up again and excel stops working, do you
> > have any ideas if my code is wrong.
> >
> > Regards
> >
> > Mark

>
> --
>
> Dave Peterson
>

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

You may want to review yesterday's suggestion. There were some things in there
that may be useful.

terilad wrote:
>
> Hi Dave,
>
> I couldn't get yesterdays solutions or codes to work as stated in todays
> discussion, and I was looking for help to revise my code as I was having
> problems with 2 pop up boxes and excel stopping. I did rate your answers on
> the 8th with your 2 responses and altered my code accordingly as Sheet1 had a
> different name and my file path was missing an s from user, so your responses
> to my questions were of great help, code only needed additional slight
> modification to resolve the issues with 2 pop up boxes and excel stopping. I
> am learning slowly with VBA. Thankyou again for your input, all help is
> greatfully appreciated.
>
> Thanks
>
> "Dave Peterson" wrote:
>
> > You didn't like yesterday's suggestions?
> >
> > terilad wrote:
> > >
> > > Hi,
> > >
> > > I have a code below and have a little problem with it, its not running
> > > smoothly for me.
> > >
> > > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, 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 +
> > > vbCritical, "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
> > >
> > > Before save event, when I click on save it pops up the msg box do you want
> > > to save as, when I click yes it pops up again and excel stops working, do you
> > > have any ideas if my code is wrong.
> > >
> > > Regards
> > >
> > > Mark

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
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

"Jacob Skaria" wrote:

> Try the below code....Please note the changes Application.EnableEvents =
> True/False and 'Cacel =True'
>
>
> 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 = "Galashiels Resources WC " & Format(Sheets("Galashiels
> Resources").Range("N2"), "dd-mmm-yy")
> userResponse = MsgBox("Do you want to save as " & strFilename, vbYesNo +
> vbCritical, "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
> Cancel = True
> End If
> Application.EnableEvents = True
>
> End Sub
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "terilad" wrote:
>
> > Hi,
> >
> > I have a code below and have a little problem with it, its not running
> > smoothly for me.
> >
> > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, 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 +
> > vbCritical, "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
> >
> > Before save event, when I click on save it pops up the msg box do you want
> > to save as, when I click yes it pops up again and excel stops working, do you
> > have any ideas if my code is wrong.
> >
> > 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 event Jon Microsoft Excel Programming 1 30th Oct 2007 05:35 PM
How do I change a Worksheet_change event to a beforesave event? =?Utf-8?B?VHVlYW5rZXI=?= Microsoft Excel Programming 5 29th Jun 2007 03:00 PM
Need help with BeforeSave event =?Utf-8?B?Q2h1Y2sgTQ==?= Microsoft Excel Programming 4 6th Mar 2007 02:15 PM
BeforeSave event =?Utf-8?B?Q2FybCBCb3dtYW4=?= Microsoft Excel Misc 4 6th Feb 2005 12:28 PM
BeforeSave event j23 Microsoft Excel Programming 0 6th Apr 2004 11:15 AM


Features
 

Advertising
 

Newsgroups
 


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