Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Prompting a predefined filename to be saved

I am using beforesaveas to prompt the save as screen with a pre-defined name.
When using the save button everything seems to be functioning ok as I am
using Cancel = True. -When using the save as function I get the pre-defined
name, however after confirming, using the save button, the screen pops up a
second time. As this file needs to be sent to end-users I don't want this to
happen. What can be done to avoid this? Find below the subroutine.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
NameToSave = Sheet15.Cells(5, 2) & " - CDP - " & Sheet15.Cells(3, 2) &
" (v" & Year(Date) & Month(Date) & Day(Date) & ")"
If Sheet15.Cells(3, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need to
select a year in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If Sheet15.Cells(5, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need to
select a country in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ", vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Prompting a predefined filename to be saved

Bart,
Assuming everything is successful, the file is saved through your last line
of code.
However, you are in the _BeforeSave event and you have not cancelled the
reason that event was called.
So, add a Cancel=True

Also, do you all the SaveAsUI checks at all ?

NickHK

"Bart V" wrote in message
...
I am using beforesaveas to prompt the save as screen with a pre-defined

name.
When using the save button everything seems to be functioning ok as I am
using Cancel = True. -When using the save as function I get the

pre-defined
name, however after confirming, using the save button, the screen pops up

a
second time. As this file needs to be sent to end-users I don't want this

to
happen. What can be done to avoid this? Find below the subroutine.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
NameToSave = Sheet15.Cells(5, 2) & " - CDP - " & Sheet15.Cells(3, 2)

&
" (v" & Year(Date) & Month(Date) & Day(Date) & ")"
If Sheet15.Cells(3, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need to
select a year in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If Sheet15.Cells(5, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need to
select a country in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ", vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Prompting a predefined filename to be saved

Nick,

I tried this already, but it did not work. I guess the problem is that I use
the save as button. With the save button everything works fine.

Bart V

"NickHK" wrote:

Bart,
Assuming everything is successful, the file is saved through your last line
of code.
However, you are in the _BeforeSave event and you have not cancelled the
reason that event was called.
So, add a Cancel=True

Also, do you all the SaveAsUI checks at all ?

NickHK

"Bart V" wrote in message
...
I am using beforesaveas to prompt the save as screen with a pre-defined

name.
When using the save button everything seems to be functioning ok as I am
using Cancel = True. -When using the save as function I get the

pre-defined
name, however after confirming, using the save button, the screen pops up

a
second time. As this file needs to be sent to end-users I don't want this

to
happen. What can be done to avoid this? Find below the subroutine.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
NameToSave = Sheet15.Cells(5, 2) & " - CDP - " & Sheet15.Cells(3, 2)

&
" (v" & Year(Date) & Month(Date) & Day(Date) & ")"
If Sheet15.Cells(3, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need to
select a year in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If Sheet15.Cells(5, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need to
select a country in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ", vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
End If

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Prompting a predefined filename to be saved

Bart,
Look at your code:
If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ", vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
'************* This is where you will perform the Save
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
'************ There is no Cancel=True
End If


NickHK


"Bart V" wrote in message
...
Nick,

I tried this already, but it did not work. I guess the problem is that I

use
the save as button. With the save button everything works fine.

Bart V

"NickHK" wrote:

Bart,
Assuming everything is successful, the file is saved through your last

line
of code.
However, you are in the _BeforeSave event and you have not cancelled the
reason that event was called.
So, add a Cancel=True

Also, do you all the SaveAsUI checks at all ?

NickHK

"Bart V" wrote in message
...
I am using beforesaveas to prompt the save as screen with a

pre-defined
name.
When using the save button everything seems to be functioning ok as I

am
using Cancel = True. -When using the save as function I get the

pre-defined
name, however after confirming, using the save button, the screen pops

up
a
second time. As this file needs to be sent to end-users I don't want

this
to
happen. What can be done to avoid this? Find below the subroutine.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
NameToSave = Sheet15.Cells(5, 2) & " - CDP - " & Sheet15.Cells(3,

2)
&
" (v" & Year(Date) & Month(Date) & Day(Date) & ")"
If Sheet15.Cells(3, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need

to
select a year in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If Sheet15.Cells(5, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need

to
select a country in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ",

vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
End If

End Sub






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Prompting a predefined filename to be saved

Nick,

I have done this, but it de-activates both the save as and the save buttons.
So no save at all happens.

Bart V

"NickHK" wrote:

Bart,
Look at your code:
If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ", vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
'************* This is where you will perform the Save
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
'************ There is no Cancel=True
End If


NickHK


"Bart V" wrote in message
...
Nick,

I tried this already, but it did not work. I guess the problem is that I

use
the save as button. With the save button everything works fine.

Bart V

"NickHK" wrote:

Bart,
Assuming everything is successful, the file is saved through your last

line
of code.
However, you are in the _BeforeSave event and you have not cancelled the
reason that event was called.
So, add a Cancel=True

Also, do you all the SaveAsUI checks at all ?

NickHK

"Bart V" wrote in message
...
I am using beforesaveas to prompt the save as screen with a

pre-defined
name.
When using the save button everything seems to be functioning ok as I

am
using Cancel = True. -When using the save as function I get the
pre-defined
name, however after confirming, using the save button, the screen pops

up
a
second time. As this file needs to be sent to end-users I don't want

this
to
happen. What can be done to avoid this? Find below the subroutine.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
NameToSave = Sheet15.Cells(5, 2) & " - CDP - " & Sheet15.Cells(3,

2)
&
" (v" & Year(Date) & Month(Date) & Day(Date) & ")"
If Sheet15.Cells(3, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need

to
select a year in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If Sheet15.Cells(5, 2) = "" Then
Answer = MsgBox("Before being able to save this file you need

to
select a country in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ",

vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
End If

End Sub








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Prompting a predefined filename to be saved

Bart,
Personally, I never use the dialog like this. I find it more reliable:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim Retval As Variant
With Application
Retval = .GetSaveAsFilename()
If Retval < False Then
.EnableEvents = False
ThisWorkbook.SaveAs Retval
.EnableEvents = True
End If
End With
Cancel = True
End Sub

NickHK

"Bart V" wrote in message
...
Nick,

I have done this, but it de-activates both the save as and the save

buttons.
So no save at all happens.

Bart V

"NickHK" wrote:

Bart,
Look at your code:
If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ",

vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
'************* This is where you will perform the Save
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
'************ There is no Cancel=True
End If


NickHK


"Bart V" wrote in message
...
Nick,

I tried this already, but it did not work. I guess the problem is that

I
use
the save as button. With the save button everything works fine.

Bart V

"NickHK" wrote:

Bart,
Assuming everything is successful, the file is saved through your

last
line
of code.
However, you are in the _BeforeSave event and you have not cancelled

the
reason that event was called.
So, add a Cancel=True

Also, do you all the SaveAsUI checks at all ?

NickHK

"Bart V" wrote in message
...
I am using beforesaveas to prompt the save as screen with a

pre-defined
name.
When using the save button everything seems to be functioning ok

as I
am
using Cancel = True. -When using the save as function I get the
pre-defined
name, however after confirming, using the save button, the screen

pops
up
a
second time. As this file needs to be sent to end-users I don't

want
this
to
happen. What can be done to avoid this? Find below the subroutine.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
NameToSave = Sheet15.Cells(5, 2) & " - CDP - " &

Sheet15.Cells(3,
2)
&
" (v" & Year(Date) & Month(Date) & Day(Date) & ")"
If Sheet15.Cells(3, 2) = "" Then
Answer = MsgBox("Before being able to save this file you

need
to
select a year in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If Sheet15.Cells(5, 2) = "" Then
Answer = MsgBox("Before being able to save this file you

need
to
select a country in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ",

vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
End If

End Sub








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Prompting a predefined filename to be saved

Nick,

Thanks for your help. I am just an occasional programmer using VB only when
I notice that excel cannot provide me with a solution.

Bart V

"NickHK" wrote:

Bart,
Personally, I never use the dialog like this. I find it more reliable:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim Retval As Variant
With Application
Retval = .GetSaveAsFilename()
If Retval < False Then
.EnableEvents = False
ThisWorkbook.SaveAs Retval
.EnableEvents = True
End If
End With
Cancel = True
End Sub

NickHK

"Bart V" wrote in message
...
Nick,

I have done this, but it de-activates both the save as and the save

buttons.
So no save at all happens.

Bart V

"NickHK" wrote:

Bart,
Look at your code:
If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ",

vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
'************* This is where you will perform the Save
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
'************ There is no Cancel=True
End If


NickHK


"Bart V" wrote in message
...
Nick,

I tried this already, but it did not work. I guess the problem is that

I
use
the save as button. With the save button everything works fine.

Bart V

"NickHK" wrote:

Bart,
Assuming everything is successful, the file is saved through your

last
line
of code.
However, you are in the _BeforeSave event and you have not cancelled

the
reason that event was called.
So, add a Cancel=True

Also, do you all the SaveAsUI checks at all ?

NickHK

"Bart V" wrote in message
...
I am using beforesaveas to prompt the save as screen with a
pre-defined
name.
When using the save button everything seems to be functioning ok

as I
am
using Cancel = True. -When using the save as function I get the
pre-defined
name, however after confirming, using the save button, the screen

pops
up
a
second time. As this file needs to be sent to end-users I don't

want
this
to
happen. What can be done to avoid this? Find below the subroutine.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
NameToSave = Sheet15.Cells(5, 2) & " - CDP - " &

Sheet15.Cells(3,
2)
&
" (v" & Year(Date) & Month(Date) & Day(Date) & ")"
If Sheet15.Cells(3, 2) = "" Then
Answer = MsgBox("Before being able to save this file you

need
to
select a year in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If Sheet15.Cells(5, 2) = "" Then
Answer = MsgBox("Before being able to save this file you

need
to
select a country in the parameter sheet.", Buttons:=48)
Cancel = True
Sheet15.Activate
Exit Sub
End If

If SaveAsUI = False Then
If MsgBox("Do you really want to save this Workbook? ",
vbYesNo) =
vbNo Then
Cancel = True
Exit Sub
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
Cancel = True
Exit Sub
End If
Else
Application.Dialogs(xlDialogSaveAs).Show (NameToSave)
End If

End Sub









Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove predefined headers PollyG Excel Discussion (Misc queries) 2 January 26th 10 12:39 AM
Combine two predefined borders sammy Excel Discussion (Misc queries) 4 September 2nd 08 06:44 PM
HelpWhy is "~$filename" 1KB copy of my saved file being created? mars373 Excel Discussion (Misc queries) 1 March 13th 08 07:18 PM
Actual Saved FileName begins with Space Jim May Excel Programming 2 April 15th 06 05:27 PM
Cycling through predefined worksheets Craig M Excel Programming 3 July 1st 04 07:58 AM


All times are GMT +1. The time now is 11:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"