ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using code in Excel (https://www.excelbanter.com/excel-discussion-misc-queries/153964-using-code-excel.html)

Cheyenne

Using code in Excel
 
Is it possible to write code in excel so that when I open a certain workbook,
it always opens to a specific sheet. I know if you save it on a specific
sheet, it will open there the next time, but I want to be able to save
anywhere in the workbook and have it open to "Sheet1" everytime.
--
Cheyenne

Bob Phillips

Using code in Excel
 
Private Sub Workbook_Open()
Worksheets("Sheet1").Activate
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Cheyenne" wrote in message
...
Is it possible to write code in excel so that when I open a certain
workbook,
it always opens to a specific sheet. I know if you save it on a specific
sheet, it will open there the next time, but I want to be able to save
anywhere in the workbook and have it open to "Sheet1" everytime.
--
Cheyenne




Jim Thomlinson

Using code in Excel
 
Open the workbook in question and right click on the XL icon next to the word
File in the upper left corner of the sceen by the work file. Select View
Code. The VBE will open up. Paste the following...

Private Sub Workbook_Open()
Sheets("Sheet1").Select
End Sub

--
HTH...

Jim Thomlinson


"Cheyenne" wrote:

Is it possible to write code in excel so that when I open a certain workbook,
it always opens to a specific sheet. I know if you save it on a specific
sheet, it will open there the next time, but I want to be able to save
anywhere in the workbook and have it open to "Sheet1" everytime.
--
Cheyenne


Mike

Using code in Excel
 
Try this
Private Sub Workbook_Open()
On Error GoTo Errhandler
Const sheetName = "Sheet1" 'Replace "Sheet1" with the name of sheet1
Dim sh1 As Worksheet
Set sh1 = Worksheets(sheetName)
sh1.Activate
Exit Sub
Errhandler:
Select Case Err
Case 9:
MsgBox "Missing" & " " _
& "Worksheet Name: " & sheetName
Exit Sub
Case Else:
MsgBox "Error#:" & Err.Number & vbCrLf & Error$
Exit Sub
End Select
End Sub

"Cheyenne" wrote:

Is it possible to write code in excel so that when I open a certain workbook,
it always opens to a specific sheet. I know if you save it on a specific
sheet, it will open there the next time, but I want to be able to save
anywhere in the workbook and have it open to "Sheet1" everytime.
--
Cheyenne



All times are GMT +1. The time now is 01:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com