Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Hi

I have code that runs on the workbook BeforeSave event.
How do I "cancel" the actual save process here? Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default BeforeSave workbook event

Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Hi

I have code that runs on the workbook BeforeSave event.
How do I "cancel" the actual save process here? Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Thanks Ron

It works. Let me ask you another question - is there a
way to have the BeforeSave and BeforeClose code NOT run?
What my code does it check that all required data is
filled-in. Now, in the design phase, I need to save
design changes and code but the BeforeSave and BeforeClose
code runs and won't allow me to save without filling in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Hi

I have code that runs on the workbook BeforeSave event.
How do I "cancel" the actual save process here?

Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default BeforeSave workbook event

Hi Cindy

Right click on the excel icon next to file on the menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("A1:A6")
If Application.WorksheetFunction.CountA(myrange) < _
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Thanks Ron

It works. Let me ask you another question - is there a
way to have the BeforeSave and BeforeClose code NOT run?
What my code does it check that all required data is
filled-in. Now, in the design phase, I need to save
design changes and code but the BeforeSave and BeforeClose
code runs and won't allow me to save without filling in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Hi

I have code that runs on the workbook BeforeSave event.
How do I "cancel" the actual save process here?

Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Hi Ron

I'm a little confused. My code is in the BeforeSave
event. What my problem is I can't save my design changes
because the "BeforeSave" codes runs and want's data filled-
in and I need to start with a "blank" form - no data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the

Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("A1:A6")
If Application.WorksheetFunction.CountA(myrange) < _
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Thanks Ron

It works. Let me ask you another question - is there a
way to have the BeforeSave and BeforeClose code NOT run?
What my code does it check that all required data is
filled-in. Now, in the design phase, I need to save
design changes and code but the BeforeSave and

BeforeClose
code runs and won't allow me to save without filling in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Hi

I have code that runs on the workbook BeforeSave

event.
How do I "cancel" the actual save process here?

Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy


.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default BeforeSave workbook event

Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Hi Ron

I'm a little confused. My code is in the BeforeSave
event. What my problem is I can't save my design changes
because the "BeforeSave" codes runs and want's data filled-
in and I need to start with a "blank" form - no data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the

Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("A1:A6")
If Application.WorksheetFunction.CountA(myrange) < _
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Thanks Ron

It works. Let me ask you another question - is there a
way to have the BeforeSave and BeforeClose code NOT run?
What my code does it check that all required data is
filled-in. Now, in the design phase, I need to save
design changes and code but the BeforeSave and

BeforeClose
code runs and won't allow me to save without filling in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message
...
Hi

I have code that runs on the workbook BeforeSave

event.
How do I "cancel" the actual save process here?
Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy


.



.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Where would I put this code?

Since it's a "template", I can't get the "on open" code to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when I only
want to disable the events to save my changes?

Sorry this is getting too complicated. I appreciate all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Hi Ron

I'm a little confused. My code is in the BeforeSave
event. What my problem is I can't save my design

changes
because the "BeforeSave" codes runs and want's data

filled-
in and I need to start with a "blank" form - no data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the

menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the

Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("A1:A6")
If Application.WorksheetFunction.CountA(myrange) <

_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Thanks Ron

It works. Let me ask you another question - is

there a
way to have the BeforeSave and BeforeClose code NOT

run?
What my code does it check that all required data is
filled-in. Now, in the design phase, I need to save
design changes and code but the BeforeSave and

BeforeClose
code runs and won't allow me to save without filling

in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi

I have code that runs on the workbook BeforeSave

event.
How do I "cancel" the actual save process here?
Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy


.



.



.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default BeforeSave workbook event

If you use it in a template you can use this as first line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Where would I put this code?

Since it's a "template", I can't get the "on open" code to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when I only
want to disable the events to save my changes?

Sorry this is getting too complicated. I appreciate all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Hi Ron

I'm a little confused. My code is in the BeforeSave
event. What my problem is I can't save my design

changes
because the "BeforeSave" codes runs and want's data

filled-
in and I need to start with a "blank" form - no data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the

menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("A1:A6")
If Application.WorksheetFunction.CountA(myrange) <

_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message
...
Thanks Ron

It works. Let me ask you another question - is

there a
way to have the BeforeSave and BeforeClose code NOT

run?
What my code does it check that all required data is
filled-in. Now, in the design phase, I need to save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without filling

in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi

I have code that runs on the workbook BeforeSave
event.
How do I "cancel" the actual save process here?
Depending
on what the code returns, I want the save process
cancelled and the workbook left on the screen.

Thanks

Cindy


.



.



.



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Ron,

I still don't know where to put the code to trigger it to
run when the user does "file-new-selects the template".

Thanks,

Cindy
-----Original Message-----
If you use it in a template you can use this as first

line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Where would I put this code?

Since it's a "template", I can't get the "on open" code

to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when I

only
want to disable the events to save my changes?

Sorry this is getting too complicated. I appreciate all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Hi Ron

I'm a little confused. My code is in the BeforeSave
event. What my problem is I can't save my design

changes
because the "BeforeSave" codes runs and want's data

filled-
in and I need to start with a "blank" form - no data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the

menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range

("A1:A6")
If Application.WorksheetFunction.CountA

(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Thanks Ron

It works. Let me ask you another question - is

there a
way to have the BeforeSave and BeforeClose code

NOT
run?
What my code does it check that all required data

is
filled-in. Now, in the design phase, I need to

save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without

filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi

I have code that runs on the workbook

BeforeSave
event.
How do I "cancel" the actual save process here?
Depending
on what the code returns, I want the save

process
cancelled and the workbook left on the screen.

Thanks

Cindy


.



.



.



.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

What event?
-----Original Message-----
If you use it in a template you can use this as first

line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Where would I put this code?

Since it's a "template", I can't get the "on open" code

to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when I

only
want to disable the events to save my changes?

Sorry this is getting too complicated. I appreciate all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Hi Ron

I'm a little confused. My code is in the BeforeSave
event. What my problem is I can't save my design

changes
because the "BeforeSave" codes runs and want's data

filled-
in and I need to start with a "blank" form - no data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the

menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range

("A1:A6")
If Application.WorksheetFunction.CountA

(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Thanks Ron

It works. Let me ask you another question - is

there a
way to have the BeforeSave and BeforeClose code

NOT
run?
What my code does it check that all required data

is
filled-in. Now, in the design phase, I need to

save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without

filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi

I have code that runs on the workbook

BeforeSave
event.
How do I "cancel" the actual save process here?
Depending
on what the code returns, I want the save

process
cancelled and the workbook left on the screen.

Thanks

Cindy


.



.



.



.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default BeforeSave workbook event

Hi cindy

In all the events that you use this as first line

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Len(ThisWorkbook.Path) = 0 Then Exit Sub

' your code

End Sub


If you open the template the events will not work because the length
of the ThisWorkbook.Path = 0

As soon as you save the template as a excel file the events are working because
you have a path (C:\test.xls or so)


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Ron,

I still don't know where to put the code to trigger it to
run when the user does "file-new-selects the template".

Thanks,

Cindy
-----Original Message-----
If you use it in a template you can use this as first

line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Where would I put this code?

Since it's a "template", I can't get the "on open" code

to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when I

only
want to disable the events to save my changes?

Sorry this is getting too complicated. I appreciate all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message
...
Hi Ron

I'm a little confused. My code is in the BeforeSave
event. What my problem is I can't save my design
changes
because the "BeforeSave" codes runs and want's data
filled-
in and I need to start with a "blank" form - no data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the
menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range

("A1:A6")
If Application.WorksheetFunction.CountA

(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Thanks Ron

It works. Let me ask you another question - is
there a
way to have the BeforeSave and BeforeClose code

NOT
run?
What my code does it check that all required data

is
filled-in. Now, in the design phase, I need to

save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without

filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Hi

I have code that runs on the workbook

BeforeSave
event.
How do I "cancel" the actual save process here?
Depending
on what the code returns, I want the save

process
cancelled and the workbook left on the screen.

Thanks

Cindy


.



.



.



.



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Oh, sorry I didn't understand. I'll give this a try!
Thanks

Cindy
-----Original Message-----
Hi cindy

In all the events that you use this as first line

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
If Len(ThisWorkbook.Path) = 0 Then Exit Sub

' your code

End Sub


If you open the template the events will not work because

the length
of the ThisWorkbook.Path = 0

As soon as you save the template as a excel file the

events are working because
you have a path (C:\test.xls or so)


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Ron,

I still don't know where to put the code to trigger it

to
run when the user does "file-new-selects the template".

Thanks,

Cindy
-----Original Message-----
If you use it in a template you can use this as first

line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Where would I put this code?

Since it's a "template", I can't get the "on open"

code
to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when I

only
want to disable the events to save my changes?

Sorry this is getting too complicated. I appreciate

all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi Ron

I'm a little confused. My code is in the

BeforeSave
event. What my problem is I can't save my design
changes
because the "BeforeSave" codes runs and want's

data
filled-
in and I need to start with a "blank" form - no

data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the
menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button

the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range

("A1:A6")
If Application.WorksheetFunction.CountA

(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Thanks Ron

It works. Let me ask you another question - is
there a
way to have the BeforeSave and BeforeClose code

NOT
run?
What my code does it check that all required

data
is
filled-in. Now, in the design phase, I need to

save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without

filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Hi

I have code that runs on the workbook

BeforeSave
event.
How do I "cancel" the actual save process

here?
Depending
on what the code returns, I want the save

process
cancelled and the workbook left on the

screen.

Thanks

Cindy


.



.



.



.



.

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default BeforeSave workbook event

This won't work for what I need to do because the path
length will be 0 because they won't save the file until
the data is verified and so the code on BeforeSave and
BeforeClose will never run.

What I really need & can't figure out is a way to run code
when the template is being used because then I could
disableevents while in design mode, save the template and
close. When the user "uses" the template, the first code
that will run is "enableevents". The problem is I can't
figure out how to run this code when the template is
being "used". The "open" event doesn't work.

I'm sorry to take up your time and appreciate your help,
but if you don't have the time, don't worry about it.
THanks

Cindy

-----Original Message-----
Hi cindy

In all the events that you use this as first line

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
If Len(ThisWorkbook.Path) = 0 Then Exit Sub

' your code

End Sub


If you open the template the events will not work because

the length
of the ThisWorkbook.Path = 0

As soon as you save the template as a excel file the

events are working because
you have a path (C:\test.xls or so)


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Ron,

I still don't know where to put the code to trigger it

to
run when the user does "file-new-selects the template".

Thanks,

Cindy
-----Original Message-----
If you use it in a template you can use this as first

line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Where would I put this code?

Since it's a "template", I can't get the "on open"

code
to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when I

only
want to disable the events to save my changes?

Sorry this is getting too complicated. I appreciate

all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi Ron

I'm a little confused. My code is in the

BeforeSave
event. What my problem is I can't save my design
changes
because the "BeforeSave" codes runs and want's

data
filled-
in and I need to start with a "blank" form - no

data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on the
menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button

the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range

("A1:A6")
If Application.WorksheetFunction.CountA

(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Thanks Ron

It works. Let me ask you another question - is
there a
way to have the BeforeSave and BeforeClose code

NOT
run?
What my code does it check that all required

data
is
filled-in. Now, in the design phase, I need to

save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without

filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Hi

I have code that runs on the workbook

BeforeSave
event.
How do I "cancel" the actual save process

here?
Depending
on what the code returns, I want the save

process
cancelled and the workbook left on the

screen.

Thanks

Cindy


.



.



.



.



.

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Ron,

I went back to "old" technology and created a sub
procedure named auto_open and enabled the events here.
This runs when the user "uses" the template file. Thanks
for all your help!

Cindy
-----Original Message-----
This won't work for what I need to do because the path
length will be 0 because they won't save the file until
the data is verified and so the code on BeforeSave and
BeforeClose will never run.

What I really need & can't figure out is a way to run

code
when the template is being used because then I could
disableevents while in design mode, save the template and
close. When the user "uses" the template, the first code
that will run is "enableevents". The problem is I can't
figure out how to run this code when the template is
being "used". The "open" event doesn't work.

I'm sorry to take up your time and appreciate your help,
but if you don't have the time, don't worry about it.
THanks

Cindy

-----Original Message-----
Hi cindy

In all the events that you use this as first line

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
If Len(ThisWorkbook.Path) = 0 Then Exit Sub

' your code

End Sub


If you open the template the events will not work

because
the length
of the ThisWorkbook.Path = 0

As soon as you save the template as a excel file the

events are working because
you have a path (C:\test.xls or so)


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Ron,

I still don't know where to put the code to trigger it

to
run when the user does "file-new-selects the template".

Thanks,

Cindy
-----Original Message-----
If you use it in a template you can use this as first
line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message
...
Where would I put this code?

Since it's a "template", I can't get the "on open"

code
to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when

I
only
want to disable the events to save my changes?

Sorry this is getting too complicated. I

appreciate
all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi Ron

I'm a little confused. My code is in the

BeforeSave
event. What my problem is I can't save my design
changes
because the "BeforeSave" codes runs and want's

data
filled-
in and I need to start with a "blank" form - no

data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on

the
menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button

the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI

As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range
("A1:A6")
If Application.WorksheetFunction.CountA
(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Thanks Ron

It works. Let me ask you another question -

is
there a
way to have the BeforeSave and BeforeClose

code
NOT
run?
What my code does it check that all required

data
is
filled-in. Now, in the design phase, I need

to
save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without
filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Hi

I have code that runs on the workbook
BeforeSave
event.
How do I "cancel" the actual save process

here?
Depending
on what the code returns, I want the save
process
cancelled and the workbook left on the

screen.

Thanks

Cindy


.



.



.



.



.

.

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default BeforeSave workbook event

Ron,

I went back to "old" technology and created a sub
procedure named auto_open and enabled the events here.
This runs when the user "uses" the template file. Thanks
for all your help!

Cindy
-----Original Message-----
This won't work for what I need to do because the path
length will be 0 because they won't save the file until
the data is verified and so the code on BeforeSave and
BeforeClose will never run.

What I really need & can't figure out is a way to run

code
when the template is being used because then I could
disableevents while in design mode, save the template and
close. When the user "uses" the template, the first code
that will run is "enableevents". The problem is I can't
figure out how to run this code when the template is
being "used". The "open" event doesn't work.

I'm sorry to take up your time and appreciate your help,
but if you don't have the time, don't worry about it.
THanks

Cindy

-----Original Message-----
Hi cindy

In all the events that you use this as first line

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
If Len(ThisWorkbook.Path) = 0 Then Exit Sub

' your code

End Sub


If you open the template the events will not work

because
the length
of the ThisWorkbook.Path = 0

As soon as you save the template as a excel file the

events are working because
you have a path (C:\test.xls or so)


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Ron,

I still don't know where to put the code to trigger it

to
run when the user does "file-new-selects the template".

Thanks,

Cindy
-----Original Message-----
If you use it in a template you can use this as first
line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message
...
Where would I put this code?

Since it's a "template", I can't get the "on open"

code
to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when

I
only
want to disable the events to save my changes?

Sorry this is getting too complicated. I

appreciate
all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi Ron

I'm a little confused. My code is in the

BeforeSave
event. What my problem is I can't save my design
changes
because the "BeforeSave" codes runs and want's

data
filled-
in and I need to start with a "blank" form - no

data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on

the
menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button

the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI

As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range
("A1:A6")
If Application.WorksheetFunction.CountA
(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Thanks Ron

It works. Let me ask you another question -

is
there a
way to have the BeforeSave and BeforeClose

code
NOT
run?
What my code does it check that all required

data
is
filled-in. Now, in the design phase, I need

to
save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without
filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Hi

I have code that runs on the workbook
BeforeSave
event.
How do I "cancel" the actual save process

here?
Depending
on what the code returns, I want the save
process
cancelled and the workbook left on the

screen.

Thanks

Cindy


.



.



.



.



.

.



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default BeforeSave workbook event

Glad you got it working

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message ...
Ron,

I went back to "old" technology and created a sub
procedure named auto_open and enabled the events here.
This runs when the user "uses" the template file. Thanks
for all your help!

Cindy
-----Original Message-----
This won't work for what I need to do because the path
length will be 0 because they won't save the file until
the data is verified and so the code on BeforeSave and
BeforeClose will never run.

What I really need & can't figure out is a way to run

code
when the template is being used because then I could
disableevents while in design mode, save the template and
close. When the user "uses" the template, the first code
that will run is "enableevents". The problem is I can't
figure out how to run this code when the template is
being "used". The "open" event doesn't work.

I'm sorry to take up your time and appreciate your help,
but if you don't have the time, don't worry about it.
THanks

Cindy

-----Original Message-----
Hi cindy

In all the events that you use this as first line

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As

Boolean, Cancel As Boolean)
If Len(ThisWorkbook.Path) = 0 Then Exit Sub

' your code

End Sub


If you open the template the events will not work

because
the length
of the ThisWorkbook.Path = 0

As soon as you save the template as a excel file the

events are working because
you have a path (C:\test.xls or so)


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message

...
Ron,

I still don't know where to put the code to trigger it

to
run when the user does "file-new-selects the template".

Thanks,

Cindy
-----Original Message-----
If you use it in a template you can use this as first
line in the event

If Len(ThisWorkbook.Path) = 0 Then Exit Sub

If the template is not saved the path length = 0

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in message
...
Where would I put this code?

Since it's a "template", I can't get the "on open"

code
to
run because the user is not actually opening it, but
calling on the template to create a new file.

And where would I put the EnableEvents = False when

I
only
want to disable the events to save my changes?

Sorry this is getting too complicated. I

appreciate
all
your help.

Cindy
-----Original Message-----
Sorry I have not understand you
I am a Stupid Dutch guy<g

You can use this to disable all the events

Application.EnableEvents = False

restore it with

Application.EnableEvents = true


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in

message
...
Hi Ron

I'm a little confused. My code is in the

BeforeSave
event. What my problem is I can't save my design
changes
because the "BeforeSave" codes runs and want's

data
filled-
in and I need to start with a "blank" form - no

data.

Cindy
-----Original Message-----
Hi Cindy

Right click on the excel icon next to file on

the
menubar
choose view code

The ThisWorkbook is now active
paste the code there

Every time you press the save(or ctrl-s) button

the
Workbook_BeforeSave is
run and check the cells for you.
If not all the cells have a value you can't save


Private Sub Workbook_BeforeSave(ByVal SaveAsUI

As
Boolean, Cancel As Boolean)
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range
("A1:A6")
If Application.WorksheetFunction.CountA
(myrange) <
_
myrange.Cells.Count Then
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Thanks Ron

It works. Let me ask you another question -

is
there a
way to have the BeforeSave and BeforeClose

code
NOT
run?
What my code does it check that all required

data
is
filled-in. Now, in the design phase, I need

to
save
design changes and code but the BeforeSave and
BeforeClose
code runs and won't allow me to save without
filling
in
required data. Any ideas?

Thanks

Cindy
-----Original Message-----
Hi Cindy

You can use

Cancel = true



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Cindy" wrote in
message
...
Hi

I have code that runs on the workbook
BeforeSave
event.
How do I "cancel" the actual save process

here?
Depending
on what the code returns, I want the save
process
cancelled and the workbook left on the

screen.

Thanks

Cindy


.



.



.



.



.

.



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
Event: open workbook Jeff Excel Discussion (Misc queries) 1 September 28th 06 02:58 PM
Event (BeforeSave) - How to test VBA code? Dave P. can you hear me now? EagleOne Excel Discussion (Misc queries) 3 September 14th 06 07:46 PM
BeforeSave event Carl Bowman Excel Discussion (Misc queries) 4 February 6th 05 12:28 PM
BeforeSave Sub Phil Hageman[_3_] Excel Programming 6 January 14th 04 10:12 AM
VBA - BeforeSave - NEED HELP HRobertson Excel Programming 2 October 23rd 03 06:50 PM


All times are GMT +1. The time now is 12:47 PM.

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"