Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default show all the rows before closing the document

Hi.
How can I prevent to close worksheet when it is used filter (4 example: for
sorting by name)? I need to have always all the rows visible when it is going
to be closed.
Please help me.
Many thanks.
Peter
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default show all the rows before closing the document

Hello Peter
Paste and amend this code with correct sheet name into Thisworkbook module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Worksheets("Sheet1")
If .AutoFilterMode Then
..ShowAllData: End If: End With
Me.Save
End Sub

HTH
Cordially
Pascal


"Peter KNAP" a écrit dans le message
de news: ...
Hi.
How can I prevent to close worksheet when it is used filter (4 example:
for
sorting by name)? I need to have always all the rows visible when it is
going
to be closed.
Please help me.
Many thanks.
Peter



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default show all the rows before closing the document

Need to amend with error handling just in case:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Worksheets("Sheet1")
If .AutoFilterMode Then
On Error Resume Next
..ShowAllData
On Error GoTo 0
End If
End With
Me.Save
End Sub

HTH
Cordially
Pascal

"papou" a écrit dans le message
de news: ...
Hello Peter
Paste and amend this code with correct sheet name into Thisworkbook
module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Worksheets("Sheet1")
If .AutoFilterMode Then
.ShowAllData: End If: End With
Me.Save
End Sub

HTH
Cordially
Pascal


"Peter KNAP" a écrit dans le message
de news: ...
Hi.
How can I prevent to close worksheet when it is used filter (4 example:
for
sorting by name)? I need to have always all the rows visible when it is
going
to be closed.
Please help me.
Many thanks.
Peter





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default show all the rows before closing the document

Hi
papou.
thank you the code does what I have asked for however one problem occurs.
when I open the worksheet only for information, use filter but accidentaly
change some cell or delete it excel does not ask me whether I want to save
changes or not.


€žpapou" napÃ*sal (napÃ*sala):

Need to amend with error handling just in case:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Worksheets("Sheet1")
If .AutoFilterMode Then
On Error Resume Next
..ShowAllData
On Error GoTo 0
End If
End With
Me.Save
End Sub

HTH
Cordially
Pascal

"papou" a écrit dans le message
de news: ...
Hello Peter
Paste and amend this code with correct sheet name into Thisworkbook
module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Worksheets("Sheet1")
If .AutoFilterMode Then
.ShowAllData: End If: End With
Me.Save
End Sub

HTH
Cordially
Pascal


"Peter KNAP" a écrit dans le message
de news: ...
Hi.
How can I prevent to close worksheet when it is used filter (4 example:
for
sorting by name)? I need to have always all the rows visible when it is
going
to be closed.
Please help me.
Many thanks.
Peter






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default show all the rows before closing the document

Peter:

To make sure that Excel prompts you to save ANY changes to the file, delete
the "Me.Save" line in the code previously offered. Change
Worksheets("Data") to be the name of your worksheet. Try the following code
(make sure it is in the "ThisWorkbook" module):

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wsData As Worksheet

On Error Resume Next

Set wsData = Worksheets("Data")

With wsData
.ShowAllData 'Needed in case Advanced Filter is used.
.AutoFilterMode = False 'Turn off AutoFilter drop-down arrows.
End With

'Display the unfiltered worksheet while
'the Save dialog box is being displayed.
Application.ScreenUpdating = True
End Sub

--
Regards,
Bill Renaud





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default show all the rows before closing the document

Thank you both. with some amendments it works well.
Peter

€žBill Renaud" napÃ*sal (napÃ*sala):

Peter:

To make sure that Excel prompts you to save ANY changes to the file, delete
the "Me.Save" line in the code previously offered. Change
Worksheets("Data") to be the name of your worksheet. Try the following code
(make sure it is in the "ThisWorkbook" module):

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wsData As Worksheet

On Error Resume Next

Set wsData = Worksheets("Data")

With wsData
.ShowAllData 'Needed in case Advanced Filter is used.
.AutoFilterMode = False 'Turn off AutoFilter drop-down arrows.
End With

'Display the unfiltered worksheet while
'the Save dialog box is being displayed.
Application.ScreenUpdating = True
End Sub

--
Regards,
Bill Renaud




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
Updating Document Without Closing and Re-Opening Randy Excel Discussion (Misc queries) 2 March 4th 09 05:01 PM
Userform won't show after closing another file Gerry O Excel Discussion (Misc queries) 8 September 7th 07 03:51 PM
Re-show userform after closing file - code help Gerry O Excel Discussion (Misc queries) 3 September 4th 07 10:52 PM
How do I undo changes after saving and closing a document astrid Setting up and Configuration of Excel 2 April 7th 06 10:30 PM
closing a word document natanz[_2_] Excel Programming 2 February 2nd 06 10:33 PM


All times are GMT +1. The time now is 05:00 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"