Consulting

Results 1 to 4 of 4

Thread: Range all sheets to cell "A1" before closing file

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    50
    Location

    Range all sheets to cell "A1" before closing file

    Friends,

    Before closing the file, I want Excel to automatically organize sheets, putting the cursor in cell "A1" of each of them and activating the first sheet, then I want it to save the workbook.

    To do this, I use the code below...

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
     
    	Sheets("Sheet5").Select
    	Range("A1").Select
     
    	Sheets("Sheet4").Select
    	Range("A1").Select
     
    	Sheets("Sheet3").Select
    	Range("A1").Select
     
    	Sheets("Sheet2").Select
    	Range("A1").Select
     
    	Sheets("Sheet1").Select
    	Range("A1").Select
     
    	ThisWorkbook.Save
     
    End Sub
    Is there any other "easier" way to do this?

    Thanks for your attention, guys.

    Hugs.

    Bruno

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim sh
    For Each sh In ActiveWorkbook.Sheets
            sh.Select
            Range("A1").Select
        Next sh
    ThisWorkbook.Save
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    We do have a Kbase entry for that: http://www.vbaexpress.com/kb/getarticle.php?kb_id=328

    But xld's code is customized for you.

  4. #4
    VBAX Regular
    Joined
    Mar 2005
    Posts
    50
    Location
    xld, thank you very much. That was exactly what I needed.

    firefytr, thanks for the link. Very good.

    And thanks to both for the quick replies.

    Hugs.

    Bruno

Posting Permissions

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