Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open specific worksheet in Excel

Status
Not open for further replies.

Stroppy

IS-IT--Management
Jul 19, 2002
293
AU
Hi all,

I have some code below that I was given a few years ago when I was making a class booking workbook. It's for opening the file so that it always opens to Sheet1. I rarely do this stuff but and I found this in "My Threads" - I do recall I had to fine tune the code below but wouldn't have a clue what it was I had to do. The sheet I want it to open to is Sheet2 named Contents.


Private Sub Workbook_Open()
Worksheets("Sheet1").Activate
End Sub

Help appreciated.

Thank you
 
BTW, when I run this whilst the workbook is open, it will activate the "contents" sheet...but it won't run on opening and I've tried with security on low, as well as selected "Enable Macros" when security on medium.
 


hi,
Code:
Private Sub Workbook_Open()
Worksheets("[b]Contents[/b]").Activate
End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Is your code stored inside the workbook object or is it saved as a macro named "Workbook_Open" in a normal module?

To be able to run your piece of code without user prompt it needs to be saved in ThisWorkbook object (in VBE it appears just above modules).

ThisWorkbook is a kind of a class object that unlike normal modules can respond to events (in your case the event that will trigger your macro to run is workbook_open action).

Just paste your code into ThisWorkbook and it should work *

*Unless it's something else that is causing the problem :)





 
Thanks to both of youb- both improved the code, and i recall Skip assisted a few years ago on this one. May I ask another detail on this...On the opening page I have a few objects - some text boxes which are linked to worksheets within and there's a border around them. The links don't work if the workbook opens and, say, the border is selected or one of the text boxes. How can I specify what cell on the Contents page is selected when the workbook opens. I've tried making up a couple of things that I thought might be work and adding to the code but so far no luck.

Thanks for helping out.

PS, Is there a good website for learning VBA? i'm thinking it's about time I learned some of the really basic stuff so i can use the Objects toolbar (whatever it's called) and start learning to play with some simple VBA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top