Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Workbook_BeforeClose trouble

Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read numerous
threads and the help in VB, but nothing I try makes the event work. I am now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this to
work please? I basically want to select a particular sheet in the workbook
before closing it. This sheet will always be in the same position in the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Workbook_BeforeClose trouble

Hi,

Try to use your own code , just a little modify:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
Me.Save
End Sub

Or :
Private Sub Workbook_Open( )
Sheets(3).Select 'select required sheet
End Sub


--
Regards,

Halim



"ewan7279" wrote:

Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read numerous
threads and the help in VB, but nothing I try makes the event work. I am now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this to
work please? I basically want to select a particular sheet in the workbook
before closing it. This sheet will always be in the same position in the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Workbook_BeforeClose trouble

Thanks for the response Halim. Unfortunately, the events still do not
activate.

However, I have found a workaround in another part of code later on to do
the same thing - select the required sheet while running rather than at the
end of code in source sheet. So simple it's stupid really...

Cheers.

"Halim" wrote:

Hi,

Try to use your own code , just a little modify:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
Me.Save
End Sub

Or :
Private Sub Workbook_Open( )
Sheets(3).Select 'select required sheet
End Sub


--
Regards,

Halim



"ewan7279" wrote:

Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read numerous
threads and the help in VB, but nothing I try makes the event work. I am now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this to
work please? I basically want to select a particular sheet in the workbook
before closing it. This sheet will always be in the same position in the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Workbook_BeforeClose trouble

Maybe this one:
Private Sub Workbook_Open( )
Thisworkbook.Sheets(3).Activate
End Sub


--
Regards,

Halim



"ewan7279" wrote:

Thanks for the response Halim. Unfortunately, the events still do not
activate.

However, I have found a workaround in another part of code later on to do
the same thing - select the required sheet while running rather than at the
end of code in source sheet. So simple it's stupid really...

Cheers.

"Halim" wrote:

Hi,

Try to use your own code , just a little modify:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
Me.Save
End Sub

Or :
Private Sub Workbook_Open( )
Sheets(3).Select 'select required sheet
End Sub


--
Regards,

Halim



"ewan7279" wrote:

Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read numerous
threads and the help in VB, but nothing I try makes the event work. I am now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this to
work please? I basically want to select a particular sheet in the workbook
before closing it. This sheet will always be in the same position in the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Workbook_BeforeClose trouble

The select sheet does work, however, you are next asking that the workbook
close in the Workbook_Before_Close event. That line is not needed. What is
needed is to Save after the sheet has been selected.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets(3).Select 'select required sheet
ActiveWorkbook.Save
End Sub

Cheers, Mike F
"ewan7279" wrote in message
...
Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read
numerous
threads and the help in VB, but nothing I try makes the event work. I am
now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this to
work please? I basically want to select a particular sheet in the
workbook
before closing it. This sheet will always be in the same position in the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Workbook_BeforeClose trouble

Hi Mike,

I have tried this by selecting a different sheet then closing the workbook.
When I open the workbook again, it has not saved on sheet(3) as expected?? I
copied the code into the sheet.

This is a frustration now, but no more than that as I have worked around it.
Would still like to understand why it's not happening...??

"Mike Fogleman" wrote:

The select sheet does work, however, you are next asking that the workbook
close in the Workbook_Before_Close event. That line is not needed. What is
needed is to Save after the sheet has been selected.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets(3).Select 'select required sheet
ActiveWorkbook.Save
End Sub

Cheers, Mike F
"ewan7279" wrote in message
...
Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read
numerous
threads and the help in VB, but nothing I try makes the event work. I am
now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this to
work please? I basically want to select a particular sheet in the
workbook
before closing it. This sheet will always be in the same position in the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
End Sub




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Workbook_BeforeClose trouble

I am not sure either. If you put this code in a new workbook with 3 sheets,
it works. That's what I did to test it. There must be some other code
somewhere that negates this action. You mentioned that the sheet has a new
name every time. I assume that happens when it is re-opened. Perhaps
something there makes it appear as though it didn't close on sheet 3. See
what I mean?
Mike F
"ewan7279" wrote in message
...
Hi Mike,

I have tried this by selecting a different sheet then closing the
workbook.
When I open the workbook again, it has not saved on sheet(3) as expected??
I
copied the code into the sheet.

This is a frustration now, but no more than that as I have worked around
it.
Would still like to understand why it's not happening...??

"Mike Fogleman" wrote:

The select sheet does work, however, you are next asking that the
workbook
close in the Workbook_Before_Close event. That line is not needed. What
is
needed is to Save after the sheet has been selected.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets(3).Select 'select required sheet
ActiveWorkbook.Save
End Sub

Cheers, Mike F
"ewan7279" wrote in message
...
Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read
numerous
threads and the help in VB, but nothing I try makes the event work. I
am
now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this
to
work please? I basically want to select a particular sheet in the
workbook
before closing it. This sheet will always be in the same position in
the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
End Sub






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Workbook_BeforeClose trouble

Hi Mike,

I have just tried this too, but it still doesn't work!! I think I'll just
give up for now - it's Friday after all...

Cheers.

"Mike Fogleman" wrote:

I am not sure either. If you put this code in a new workbook with 3 sheets,
it works. That's what I did to test it. There must be some other code
somewhere that negates this action. You mentioned that the sheet has a new
name every time. I assume that happens when it is re-opened. Perhaps
something there makes it appear as though it didn't close on sheet 3. See
what I mean?
Mike F
"ewan7279" wrote in message
...
Hi Mike,

I have tried this by selecting a different sheet then closing the
workbook.
When I open the workbook again, it has not saved on sheet(3) as expected??
I
copied the code into the sheet.

This is a frustration now, but no more than that as I have worked around
it.
Would still like to understand why it's not happening...??

"Mike Fogleman" wrote:

The select sheet does work, however, you are next asking that the
workbook
close in the Workbook_Before_Close event. That line is not needed. What
is
needed is to Save after the sheet has been selected.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets(3).Select 'select required sheet
ActiveWorkbook.Save
End Sub

Cheers, Mike F
"ewan7279" wrote in message
...
Hi All,

I am having real trouble with 'Workbook_BeforeClose'. I have read
numerous
threads and the help in VB, but nothing I try makes the event work. I
am
now
so confused I'm stumped.

Can someone give me a step by step guide to what I need to do for this
to
work please? I basically want to select a particular sheet in the
workbook
before closing it. This sheet will always be in the same position in
the
workbook, but will have a different name every time.

I have tried this code to no avail:

Private Sub Workbook_BeforeClose( )
Sheets(3).Select 'select required sheet
ActiveWorkbook.Close 'close on required sheet
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
Workbook_BeforeClose? kartune85[_11_] Excel Programming 6 June 26th 06 08:53 AM
Workbook_BeforeClose Alan McQuaid via OfficeKB.com Excel Programming 3 June 13th 06 04:36 PM
workbook_beforeClose GB Excel Programming 2 March 1st 06 12:39 AM
Workbook_BeforeClose Andrzej Excel Programming 1 June 12th 05 10:01 PM
Workbook_BeforeClose PO Excel Programming 2 January 30th 05 05:07 PM


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

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

About Us

"It's about Microsoft Excel"