Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to open a specific worksheet via code from workbook_open

I have a combobox which is populated with all the worksheets within the
workbook. The controlsource of the combobox is linked to cell c5 on Sheet1

My question is how do i make the Excel workbook open at the worksheet which
is detailed within the combobox linked cell.

I've been previously using in the Workbook_Open procedu-

Worksheets(Worksheets("sheet1").Range("c5").Value)

but the above code doesnt seem to work.

Hope you can help!

Cheers
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default How to open a specific worksheet via code from workbook_open

Private Sub Workbook_Open()
'Sheet CodeName
'http://www.ozgrid.com/VBA/excel-vba-sheet-names.htm
Sheet1.Activate
End Sub



"Martin Parker" wrote in message
...
I have a combobox which is populated with all the worksheets within the
workbook. The controlsource of the combobox is linked to cell c5 on Sheet1

My question is how do i make the Excel workbook open at the worksheet
which
is detailed within the combobox linked cell.

I've been previously using in the Workbook_Open procedu-

Worksheets(Worksheets("sheet1").Range("c5").Value)

but the above code doesnt seem to work.

Hope you can help!

Cheers


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default How to open a specific worksheet via code from workbook_open

Worksheets(Worksheets("sheet1").Range("c5").Value) .Activate


"Martin Parker" wrote:

I have a combobox which is populated with all the worksheets within the
workbook. The controlsource of the combobox is linked to cell c5 on Sheet1

My question is how do i make the Excel workbook open at the worksheet which
is detailed within the combobox linked cell.

I've been previously using in the Workbook_Open procedu-

Worksheets(Worksheets("sheet1").Range("c5").Value)

but the above code doesnt seem to work.

Hope you can help!

Cheers

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to open a specific worksheet via code from workbook_open

Thanks that works great, however, one problem, if the user has previously
closed the app on the worksheet the code is referring to, I get a runtime
error on workbook open.

How would i code to check if the worksheet requested to open up at workbook
open is already activated?

Hope this makes sense!

Cheers

"JLatham" wrote:

Worksheets(Worksheets("sheet1").Range("c5").Value) .Activate


"Martin Parker" wrote:

I have a combobox which is populated with all the worksheets within the
workbook. The controlsource of the combobox is linked to cell c5 on Sheet1

My question is how do i make the Excel workbook open at the worksheet which
is detailed within the combobox linked cell.

I've been previously using in the Workbook_Open procedu-

Worksheets(Worksheets("sheet1").Range("c5").Value)

but the above code doesnt seem to work.

Hope you can help!

Cheers

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to open a specific worksheet via code from workbook_open

This is the code i'm using that gets a runtime error application defined or
object defined error:-

If ActiveSheet.Name = Worksheets("sheet1").Range("c5") Then
MsgBox "Already here on... " & ActiveSheet.Name
Else
'MsgBox "Not here!"
Worksheets(Worksheets("sheet1").Range("c5").Value) .Activate
End If

Hope you guys can help!

"Martin Parker" wrote:

Thanks that works great, however, one problem, if the user has previously
closed the app on the worksheet the code is referring to, I get a runtime
error on workbook open.

How would i code to check if the worksheet requested to open up at workbook
open is already activated?

Hope this makes sense!

Cheers

"JLatham" wrote:

Worksheets(Worksheets("sheet1").Range("c5").Value) .Activate


"Martin Parker" wrote:

I have a combobox which is populated with all the worksheets within the
workbook. The controlsource of the combobox is linked to cell c5 on Sheet1

My question is how do i make the Excel workbook open at the worksheet which
is detailed within the combobox linked cell.

I've been previously using in the Workbook_Open procedu-

Worksheets(Worksheets("sheet1").Range("c5").Value)

but the above code doesnt seem to work.

Hope you can help!

Cheers



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to open a specific worksheet via code from workbook_open

I'd use something like:

Option Explicit
Private Sub Workbook_Open()
On Error Resume Next
Me.Worksheets(cstr(Me.Worksheets("sheet1").Range(" c5").Value)).Select
If Err.Number < 0 Then
Err.Clear
MsgBox "Couldn't go to the sheet!"
End If
On Error GoTo 0
End Sub

There are a couple of reasons this could break.

You could have a bad name in Sheet1!c5 -- maybe the sheet has been deleted or
the value in the cell isn't legal (like a date mm/dd/yyyy) or you the worksheets
are named 1, 2, 3, ... and the value in the cell is numeric.

Or maybe Sheet1 doesn't exist anymore.



Martin Parker wrote:

This is the code i'm using that gets a runtime error application defined or
object defined error:-

If ActiveSheet.Name = Worksheets("sheet1").Range("c5") Then
MsgBox "Already here on... " & ActiveSheet.Name
Else
'MsgBox "Not here!"
Worksheets(Worksheets("sheet1").Range("c5").Value) .Activate
End If

Hope you guys can help!

"Martin Parker" wrote:

Thanks that works great, however, one problem, if the user has previously
closed the app on the worksheet the code is referring to, I get a runtime
error on workbook open.

How would i code to check if the worksheet requested to open up at workbook
open is already activated?

Hope this makes sense!

Cheers

"JLatham" wrote:

Worksheets(Worksheets("sheet1").Range("c5").Value) .Activate


"Martin Parker" wrote:

I have a combobox which is populated with all the worksheets within the
workbook. The controlsource of the combobox is linked to cell c5 on Sheet1

My question is how do i make the Excel workbook open at the worksheet which
is detailed within the combobox linked cell.

I've been previously using in the Workbook_Open procedu-

Worksheets(Worksheets("sheet1").Range("c5").Value)

but the above code doesnt seem to work.

Hope you can help!

Cheers


--

Dave Peterson
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
How to open a specific worksheet via code from workbook_open Martin Parker[_2_] Excel Programming 1 April 9th 10 08:16 PM
Open Specific Worksheet cargor Excel Discussion (Misc queries) 4 July 12th 06 06:04 PM
Open on specific worksheet Adrian Excel Discussion (Misc queries) 1 October 27th 05 05:33 PM
VB code to make Excel open in a specific worksheet OscarC Excel Programming 2 December 7th 04 09:57 PM
VBA code to open a specific worksheet MohK Excel Programming 2 October 29th 03 06:02 PM


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