+ Reply to Thread
Results 1 to 2 of 2

Help on Workbook close and workbook save events

Hybrid View

  1. #1
    Adam Harding
    Guest

    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. #2
    JNW
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1