Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Help on Workbook close and workbook save events

Have written the following code for before close and before save

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("A13:G512").Select
Selection.Sort Key1:=Range("A13"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Range("A13").Select
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Range("A13:G512").Select
Selection.Sort Key1:=Range("A13"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Range("A13").Select
End Sub

However I am getting a a 1004 error can you help. I feel i am so close but
am having no joy.

thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default Help on Workbook close and workbook save events

Is the file read only?

Found this:

[Method name] method of [object] class failed (Error 1004)
An external error occurred, such as a failure to read or write from a file.
The method cannot be used on the object. Possible reasons include the
following:

€¢ An argument contains a value that isn't valid. A common cause of this
problem is an attempt to access an object that doesn't exist [for example,
you tried to use Workbooks(5) when there were only three workbooks open].
€¢ The method cannot be used in the applied context. For example, some Range
object methods require that the range contain data; if the range doesn't
contain data, the method fails.
€¢ An external error occurred, such as a failure to read or write from a
file.
For more information about the method, search Help for the method name.


"Adam Harding" wrote:

Have written the following code for before close and before save

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("A13:G512").Select
Selection.Sort Key1:=Range("A13"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Range("A13").Select
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Range("A13:G512").Select
Selection.Sort Key1:=Range("A13"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Range("A13").Select
End Sub

However I am getting a a 1004 error can you help. I feel i am so close but
am having no joy.

thanks in advance

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
close workbook without saving or promt to save ATVNSHANE Excel Discussion (Misc queries) 3 February 4th 10 03:57 PM
Macros on workbook close and save Ade P Excel Programming 1 May 2nd 05 11:39 AM
On close and before save events. Austin Excel Programming 1 October 5th 04 02:05 PM
Close Workbook without displaying message to Save Vinay[_2_] Excel Programming 2 June 10th 04 05:05 PM
Events for workbook close Aaron Queenan Excel Programming 6 July 15th 03 09:09 PM


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